Um... err... Sorry, I wasn't talking about making a copy of anything. I'm sorry if...
class Manager{
Store(Base object){
object.SecretFunction(42);
// Store the base class somewhere.
}
} // end manager
... threw you off.
It was for demonstrative purposes only. Ignore the fact that this class stores something, the purpose here is to show that class Manager is accessing a private function from some other class. Pretend that the function Store is whatever function you like.
I know I wasn't particularly clear with my original post, being in a hurry and all, but allow me to explain better what is in my head.
Class Base, and class Manager are a set in a library I'm trying to design, and as such I want Manager to have access to Base's private, and protected data.
People using the library inherit from Base and write code for Function.
class Base {
public:
virtual Function = 0;
}
class Derived inherits from class Base {
public:
Function() {
// Users put their code here.
}
}
The goal here is that the newly derived class (creatively named Derived) has access to some important data which it inherited, but didn't have to set up. When an instance of Derived is handed to Manager, Manager will treat it like an instance of Base and access SecretFunction.
Store(Base object) {
object.SecretFunction(42);
}
SecretFunction's job is to set up the protected data then call Function (the library user's code).
SecretFunction(int num) {
number = num;
Function();
return;
}
Specifically, what I want to know is...
Can Manager access the private functions and the protected data in Base, even though it has an instance of Derived?
And,
Can SecretFunction make a call to Function in the setup I have here?
I think the answer is yes to both questions, but because I can't test it right now I don't know and need a bit of help.