error: cannot convert 'C (*)()' to 'C*' in initialization

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
Drop the () on line 6.

The compiler thinks line 6 is a declaration of a function named obj that take no parameters and returns a C.
Topic archived. No new replies allowed.