This code looks simple but I am embarrassed to say I can not figure out the compile error.
The commented code is similar and it compiles.
Why does "C* ptrObj = &obj;" get a compile error?
Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class C
{
void func() {}
};
C obj();
C* ptrObj = &obj; //error: cannot convert 'C (*)()' to 'C*' in initialization
/*
int obj;
int* ptrObj = &obj; // this compiles
*/
int main()
{
}
D:\demo_MinGW>g++ temp1.cpp
temp1.cpp:7:14: error: cannot convert 'C (*)()' to 'C*' in initialization
C* ptrObj = &obj; //error: cannot convert 'C (*)()' to 'C*' in initialization