I am having problems with something that should be simple. Just trying to initialize a member variable and then use a friend function to display the private member variable. As you can see, I pass in a number through int x, then try to initialize private member variable to that in the constructor and then display it but I still cannot access it. Any ideas on what I am doing wrong. I know this is a simple program but I would rather learn it this way then apply it to my school program.
Code:#include <iostream> using namespace std; class MyClass { int a; public: MyClass::MyClass(int x) { a=x; } friend void display(); }; void display(MyClass number) { cout << number.a << "\n"; } main() { MyClass number(200); display(); return 0; }