View Single Post
Old 02-08-2005, 07:27 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
It is very hard to see what you're up to. So I can't make a proper design. Below is a swing in the air regarding your intentions. See if you can learn the things you want to learn:
Code:
[#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;

//------------------------------------------------

class A
{
public:
  A(){}
  vector<string>& model_lookupTable()
  {
    return ModelLookupTable_;
  }
private:
  vector <string> ModelLookupTable_;
};

//------------------------------------------------

class Base
{
public:
  Base() {}
  Base( vector<string>& lt ) : Base_LookupTable_(lt)
  {
    Base_LookupTable_.push_back("Base1");
    Base_LookupTable_.push_back("Base2");
    Base_LookupTable_.push_back("Base3");
  }
  //
  vector<string> base_lookupTable() const
  {
    return Base_LookupTable_;
  }
  //
  virtual void some_function()=0;
protected:
  vector<string> Base_LookupTable_;
  int members;
};

//------------------------------------------------

class Derived : public Base
{
  public:
    Derived(){}
    Derived(vector<string>& lt) :
      Base(lt)
    {}

    //Lookup_Table ...  do something with it.
    //Important thing is that we are now accessing the member from class A!!
    void some_function()
    {
      Base_LookupTable_.push_back("Derived1");
      Base_LookupTable_.push_back("Derived2");
      Base_LookupTable_.push_back("Derived3");
    }
};

//------------------------------------------------

int main()
{
  //Let us create a vector.
  A myA;
  myA.model_lookupTable().push_back("A1");
  myA.model_lookupTable().push_back("A2");
  myA.model_lookupTable().push_back("A3");
  
  //The vecor created (above) will be modified by class Base constructor.
  Base* myInstance = new Derived( myA.model_lookupTable() );
  //And then the vector will be modified by class Derived method.
  myInstance->some_function();
  
  //What has the Base/Derived class in store?
  for(std::size_t i = 0; i < myInstance->base_lookupTable().size(); ++i)
  {
    cout<<myInstance->base_lookupTable()[i]<<endl;
  }
  cout<<endl;
  //What has classs A in store?
  for(std::size_t i = 0; i < myA.model_lookupTable().size(); ++i)
  {
    cout<<myA.model_lookupTable()[i]<<endl;
  }
  
  return 0;
}
__________________
Valmont is offline   Reply With Quote