一旦我知道它属于哪个主题,我很乐意将这个线程的标题更改为更合适的名称。
如果我更改导致错误的构造函数的参数,则没有错误。
仅当我包含该确切的构造函数时才会发生此错误:
error: no matching function for call to 'Object::Object(Object)'
note: candidates are: Object::Object(Object&)
note: Object::Object()
代码:
#include <iostream>
using namespace std;
class Object {
public:
Object() {} /* default constructor - no problems at all */
Object( Object & toCopy ) {} /* Cause of error, but no error when commented out */
Object func() {
Object obj;
return obj;
}
};
int main() {
Object o = o.func(); /* this is the line that the error is actually on */
return 0;
}