friend class with forward class declaration does not compile
问题 This a basic program to understand how to use friend class in C++. Class xxx has a class yyy object using friend . Since class yyy is defined after class xxx I have declared class yyy using forward declaration. #include<iostream> using std::cout; using std::endl; class yyy; //Forward Declaration of class yyy class xxx{ private: int a; public: xxx(){a=20;yyy y2;y2.show();} //Error// void show(){cout<<"a="<<a<<endl;} friend class yyy; //Making class yyy as freind of class xxx }; class yyy{