The question is in reference to this, which was posted a little while earlier.
While the OP was happy accepting the answer which solved his problem I was a little intrigued with a detail as to why compiler gave a seemingly wrong error.
Below is a small code sample I created to demonstrate the same:
class YourClass
{
};
class YourClass2
{
};
class MyClass
{
public:
void doSomething(YourClass2 obj)
{
//Nothing more Interesting to do
}
};
int main()
{
YourClass *ptr = new YourClass();
MyClass obj;
obj.doSomething(ptr);
return 0;
}
Compiling this with GCC(4.3.4) gives a seemingly strange error result:
prog.cpp: In function ‘int main()’:
prog.cpp:23: error: no matching function for call to ‘MyClass::doSomething(YourClass*&)’
prog.cpp:13: note: candidates are: void MyClass::doSomething(YourClass2)
So the Question is:
Why does the compiler treat the call,
obj.doSomething(ptr);
as call to a function with prototype,
MyClass::doSomething(YourClass*&)
and not
MyClass::doSomething(YourClass*)
which seems to be the obvious case.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…