Linked Class in C++? -


As everyone knows: to create a program dynamic, create link lists with C / C ++ Is possible. But now, I am programming a "linked class" in C ++. My parents "games" should have a variable number of elements. And each element is a class. So I have programmed it:

  class games: public level {private: ELEMENT * startPointer; Public: Games () {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 * next indicator) {next = nextPointer; }}   

My problem: I have never heard of a link class before, and I'm not sure I should use it.
Professional programmers use such methods (and is it useful?), Or are there better ways to do this?

Are there better ways to do this?

Yes there is one:

  class games: public level {personal: std :: vector & lt; ELEMENT & gt; Elements; ...}; Use standard library containers:  
  • Typically, std :: vector & lt; & Gt; Use .
  • If you need specificity, use std :: set << li>
  • Use std :: map & lt; & Gt; / Code>
  • If you need to insert or delete items from containers very often or in a very fast way, std :: list & lt; & Gt; Use or std :: set & lt; & Gt;
  • There are other considerations To effectively use standard containers, consult a good book.

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -