gpt4 book ai didi

c++ - 如何提供默认参数作为这个对象?

转载 作者:行者123 更新时间:2023-11-30 01:00:30 24 4
gpt4 key购买 nike

我想要这样的声明:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com