1. If I instantiate objects like this, no error occurs.
class A {};
int main () {
A a = A ();
A &b = a;
return 0;
}
2. If I instantiate object this way, compiler reports error C2440: 'initializing' : cannot convert from 'A (__cdecl \*)(void)' to 'A &'
when a
's reference is copied to b
.
class A {
};
int main () {
A a();
A &b = a;
return 0;
}
3. But if I add a constructor with parameters and pass in some argument(s) to this ctor during instantiation in the second way, there is no error!
class A {
public:
A (int a) {}
};
int main () {
A a(5);
A &b = a;
return 0;
}
Can anyone please explain this?