Use inheritance or composition:
Inheritance:
Code:
class example
{
...
};
class chair : public example
{
... // stuff added to example content
};
Composition:
Code:
class example
{
...
};
class chair
{
example x;
... // other stuff.
};
both of these will allow chair to use setX(), since setX is a public function, and thus allows anything that knows of an example instance to use this function.
If you make the function private then only the class itself can use it - no manner of inheritance or conposition will change that. If you make it protected, only classes that inherit from the base-class can use the method. Protected is, in my opinion, quite useless - it is just like putting a sign saying "don't walk on the grass" - it will only prevent people who follow rules from doing so - since any other class can just inherit from the class and then use your "protected" content with no repercussion. Private is like putting a fence around the grass - it is a physical barrier for other users to prevent it from being abused [there are ways around fences too - you can climb over or use power-tools to cut through them, and in C++ those tools are pointers and casts - but then we're probably going to get noticed!]
--
Mats