Although I think you mean something like this:
Code:
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;
using std::ostream;
//------------------------------------------------
class A
{
public:
A(){}
vector<string>& model_lookupTable()
{
return ModelLookupTable_;
}
private:
vector<string> ModelLookupTable_;
};
//------------------------------------------------
class Base
{
public:
Base() {}
Base( A& a ) : theA(a)
{
theA.model_lookupTable().push_back("Base") ;
}
virtual void some_function()=0;
const vector<string>& get_table()
{
return theA.model_lookupTable();
}
protected:
A theA;
};
//------------------------------------------------
class Derived : public Base
{
public:
Derived(){}
Derived(A& a) : Base(a) {}
void some_function()
{
theA.model_lookupTable().push_back("Derived");
}
};
//------------------------------------------------
int main()
{
A myA;
//Modfiy property directly.
myA.model_lookupTable().push_back("A");
//Constructor of class Base will modify property of class A.
Base* myInstance = new Derived( myA );
//Constructor of class Derived will finally modify property of class A.
myInstance->some_function();
//So what do we got for myInstance?
for(unsigned i = 0; i < myInstance->get_table().size(); ++i)
{
cout<<"From instance: "<< myInstance->get_table()[i]<<endl;
}
//And class A?
for(unsigned i = 0; i < myA.model_lookupTable().size(); ++i)
{
cout<<"Class A: "<< myA.model_lookupTable()[i]<<endl;
}
delete myInstance;
return 0;
}