【发布时间】:2020-08-14 04:48:02
【问题描述】:
class C {
private:
int n{ 5 };
public:
int return5() { return 5; }
void f(int d = return5()) {
}
void ff(int d = n) {
}
};
为什么我不能用成员类初始化函数的默认参数?我收到一个错误:非静态成员引用必须是相对于特定对象的。
我认为问题在于尚未实例化任何对象,但是有什么方法可以做到吗?
【问题讨论】:
-
您确定要
return5而不是returnN?如您所见,return5还不错。问题标题中暗示的void f(int d = n)...
标签: c++ parameters default-arguments