As everyone knows: It’s possbile to create linkes lists with C / C++ in order to make a program dynamical.
But now, I’m programming a “linked Class” in c++.
My Parent-Class “GAME” should have a variable number of Elements. And each Element is a class.
So I programmed this:
class GAME : public LEVEL
{ private:
ELEMENT *startPointer;
public:
GAME()
{ startPointer=NULL;
}
initGame()
{ p=aStartPointer;
while(p!=NULL);//This loop is based on a linked list, so its dynamic
{ startPointer=new ELEMENT(startPointer);
p=p->next;
}
}
}
class ELEMENT
{ private:
ELEMENT *next;
public:
ELEMENT(ELEMENT* nextPointer)
{ next=nextPointer;
}
}
My Problem: I never heard about a linked class before, and I’m not sure if I should use it.
Does professional programmers use such methods (and is it usefull?), or are there better Methods to do this?
Yes. Here is one:
Use the standard library containers:
std::vector<>.std::set<>std::map<>std::list<>orstd::set<>