"calls constructor, not type" in g ++ 4.4.7
I have the following simple C ++ code:
#include <cstdio>
class A
{
public:
A(int y) : x(y) {}
A& operator=(const A& rhs);
int x;
};
A::A& A::operator=(const A& rhs) { this->x = rhs.x; return *this; }
int main(int, char**)
{
A a1(5);
A a2(4);
printf("a2.x == %d\n", a2.x);
a2 = a1;
printf("a2.x == %d\n", a2.x);
return 0;
}
Line 11, where the definition of the function A operator=()is equal, garbled ... or at least I think so. As expected, g ++ 4.7.4, as well as every new version of GCC I tried, produces the following error:
main.cpp:11:1: error: ‘A::A’ names the constructor, not the type
Oddly enough, g ++ 4.4.7 will compile this program without warnings and even prints 4 and 5, as you would expect if line 11 was spelled correctly (i.e. using A&instead A::A&).
- , g++ 4.4.7? ( , )? , , operator=().
g++ . 4.5.0, 4.4.7 .
:
cc1plus . , , A:: A ( )
struct A { }; int main() { A::A a; // should be an ERROR }
, A::A , . , , 4.5.0.