Hi,
I am designing a class having interlinked object...a sort of tree. The code for each element of tree looks like :

Class C;
class Element {
public:
    int key;
    string payload;
    C * next;
};

But the object of Element is becoming too heavy because of use of string class. I want to design a separate vector class for storing these strings value and refer them by just using a iterator. So the code will look something like this:

Class C;
class Element {
public:
    int key;
   vector <string>::iterator payload;
    C * next;
};

The easier way is to declare a vector string as global variable and use global function to insert and delete. But I want to do this using a separate class for the whole vector string with member function for insertion and deletion. Any suggestion how to proceed? Couldnt find out a proper architecture...

Probabily not what you want -- But why not have an object class that holds the strings and whatever else you need. Then have each of the classes C+Element as you have except that Element has a pointer to the container class. [version of the handle class -- see Ruminations on C++ -- Koenig amoung many other places.]

However, I am not a professional software designer so I would defer to them and anyone with lots of real experience.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.