I have two errors :
return type 'class A' is incomplete and conversion from 'B' to non-scalar type 'A' requested.
I'm not sure what I am doing wrong because I am not very good on writing classes in C++. Any help would be appreciated! Thanks.
This is the code :
#include <iostream>
using namespace std;
class A;
class B
{
int x;
public: B(int i=10) {x=i;}
operator A();
};
B::operator A() {return x;}
class A
{
int x;
public:A(int i=7) {x=i;}
int get_x() {return x;}
};
int main()
{
B b;
A a=b;
cout<<a.get_x();
return 0;
}