So, in main() there's a call to A::do_stuff(), which returns a pointer to B. The problem is that I want to store these pointers in a vector, but I can't make a vector of B* in main(), because it's not public. I don't want the whole world to have access to B, and I don't need to modify B directly (other than by the "correct" way) - I just need to store some pointers. What's the right way to go about doing this without breaking things?

12-09-2008

scwizzo

Make a public function that has access to B, and does what you want. That way you can access B and do what you want, but the whole world can't access B and do what they want.

12-09-2008

brewbuck

Make B public, but make everything INSIDE B private, with A being a friend class. Now you can pass around pointers to B as much as you want, but only A can do anything with them.

12-09-2008

Cogman

If you want Private data to be private, then you mark it private. By trying to access data in the main function outside the class you really don't want your data to be private but public. If you don't treat your data like it is private why should anyone else?

12-09-2008

Mostly Harmless

Quote:

Originally Posted by brewbuck

Make B public, but make everything INSIDE B private, with A being a friend class. Now you can pass around pointers to B as much as you want, but only A can do anything with them.

After reading this, then looking at my code, I realized how wrong my original design was. It's great how a tiny change in perspective can make everything fall into place. Thanks for the insight.