Nonstatic member as a default argument of a nonstatic member function

后端 未结 9 1077
攒了一身酷
攒了一身酷 2020-11-28 05:56
struct X
{
   X():mem(42){}
   void f(int param = mem) //ERROR
   {
      //do something
   }
private: 
   int mem;
};

Can anyone give me just one

9条回答
  •  生来不讨喜
    2020-11-28 06:30

    ISO C++ section 8.3.6/9

    a nonstatic member shall not be used in a default argument expression, even if it is not evaluated, unless it appears as the id-expression of a class member access expression (5.2.5) or unless it is used to form a pointer to member (5.3.1).

    Also check out the example given in that section.

提交回复
热议问题