0
why friend function not working in C++?
// compiler show error. // https://www.sololearn.com/compiler-playground/cno6jtPGQqyW #include <iostream> using namespace std; class B; class A { private: void printName() { cout << "xyz\n"; } void printWeight() { cout << "40kg\n"; } friend void B::showInfo(A); }; class B { public: void showInfo(A obj) { obj.printName(); obj.printWeight(); } }; int main() { A objA; B objB; objB.showInfo(objA); return 0; }
4 Answers
+ 4
Rishi ,
Lots of mistake in your code..
#Missing class A declaration..
#For fix the error, need to reorder the class declarations so that class B is declared before class A.
See this modified code..
https://code.sololearn.com/cwt53IJ16zQ9/?ref=app
+ 1
Rishi Try again..
0
Worked!
0
Aziz