How can you modify an object without calling member functions?

后端 未结 7 2465
不知归路
不知归路 2021-02-13 15:41

At 3.10/10, the standard says:

An lvalue for an object is necessary in order to modify the object except that an rvalue of class type can also be used to

7条回答
  •  不思量自难忘°
    2021-02-13 16:11

    A member function can change the member directly, but it can also delegate that responsibility:

    struct Foo {
      int x;
      void Bar() { scanf("%d", &x); }
    };
    

    The current wording of the standard has the advantage that one doesn't need to argue whether this is a case of Bar changing the object. If we'd agree that scanf changes the object, then that's just another example.

提交回复
热议问题