J
Jess
Hello,
I'd like to declare two classes to be friend classes, I did the
following:
#include<iostream>
using namespace std;
class A{
friend class B;
public:
int x;
B b;
A():x(10),y(20){}
private:
int y;
};
class B{
friend class A;
public:
int u;
B():u(30),v(40){}
A a;
private:
int v;
};
int main(){
B b;
return 0;
}
However, the compiler error said "'B' does not name a type". I think
this is because I haven't declared
B when I introduced it into A. But if I declare class B first, then
the same problem will happen to the declaration of B. What should I
do?
Thanks,
Jess
I'd like to declare two classes to be friend classes, I did the
following:
#include<iostream>
using namespace std;
class A{
friend class B;
public:
int x;
B b;
A():x(10),y(20){}
private:
int y;
};
class B{
friend class A;
public:
int u;
B():u(30),v(40){}
A a;
private:
int v;
};
int main(){
B b;
return 0;
}
However, the compiler error said "'B' does not name a type". I think
this is because I haven't declared
B when I introduced it into A. But if I declare class B first, then
the same problem will happen to the declaration of B. What should I
do?
Thanks,
Jess