I'm new on using class.

Other than declare as friend class or declare static for the specific file to share variables/functions. Is there any other way?

I have inherit few classes and wrote into few *.cpp file. I can't extern a static file, so is that mean i just only can share members through friend classes?

Recommended Answers

All 2 Replies

Use public get methods to access the member variables. Leave the variables themselves private in order to protect them from outside modification, but with a get methods, such as "const member_type getMemberName() const", you can access the variable data safely, and easily.

Make the member function a actual function. If more than one class actually needs it, then its nor correct to make it a member function for one class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.