我想要这样的声明:
void Date::get_days_name(const Date& = this)
我会理解,如果没有提供参数,请使用此对象作为参数。出于某种原因,在 VS 中我收到错误消息:
'错误 1 error C2355: 'this': can only be referenced inside non-static member'
知道我做错了什么吗?
最佳答案
你可以重载函数:
void get_days_name(const Date&) const;
void get_days_name() const {
get_days_name(*this);
}
(顺便说一句,this
是一个指针,而不是引用。)
关于c++ - 如何提供默认参数作为这个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2571751/