+ 2
Why compiler is giving error in the second code and not in first one ?
//First code class A { public: int A; }; int main() { A o; o.A=5; cout<<o.A; return 0; } //Second code class A { public: int A; A(){} }; int main() { A o; o.A=5; cout<<o.A; return 0; } /* Note : the variable and class has same name in the both cases but compiler is giving error only when we putting a constructor in the class A */
2 ответов
+ 3
The constructor has the same name as the class which is A. But you can't have two members with the same name so the integer called A conflicts with the constructor called A as well. Solution: rename the integer
+ 2
Oh so the problem is with constructor and variable ok i got it....