0

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...

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by StuXYZ
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.