I tried playing around with OOP which made me write the following code :
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
class A
{
int a;
public:
A()
{
cout << "implicit constr\n";
a = 0;
}
A(const int& x)
{
a = x;
cout << "parameter constr\n";
}
A(const A& x)
{
a = x.a;
cout << "copy constr\n";
}
A& operator = (const A& x)
{
a = x.a;
cout << "equal operator\n";
return *this;
}
void print()
{
cout << "\n" << a << "\n";
}
};
int main()
{
A a(3);
A b( A(a));
b.print();
return 0;
}
The given error is : error: request for member 'print' in 'b', which is of non-class type 'A(A)'| I used typeid to verify what object does b become?
The name of b-s class is different from object a's class. ( a class typeid name is A1 while b's class typeid name is F1_A1LS ).
Well if i modify A b( A(a)) to A b((A(a))) it works perfect.
Can someone explain to my why this doesn't work?