您好,我在下面有这样的代码,但我不知道为什么它不起作用。
class Clazz2;
class Clazz
{
public:
void smth(Clazz2& c)
{
}
void smth2(const Clazz2& c)
{
}
};
class Clazz2
{
int a,b;
};
int main()
{
Clazz a;
Clazz2 z;
a.smth(z);
//a.smth(Clazz2()); //<-- this doesn't work
a.smth2(Clazz2()); // <-- this is ok
return 0;
}
我有编译错误:
g++ -Wall -c "test.cpp" (in directory: /home/asdf/Desktop/tmp)
test.cpp: In function ‘int main()’:
test.cpp:26:17: error: no matching function for call to ‘Clazz::smth(Clazz2)’
test.cpp:26:17: note: candidate is:
test.cpp:5:7: note: void Clazz::smth(Clazz2&)
test.cpp:5:7: note: no known conversion for argument 1 from ‘Clazz2’ to ‘Clazz2&’
Compilation failed.