Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualL. Spiro

Posted 30 November 2012 - 02:59 AM

dynamically allocated memory in classes vs putting it in structs.

Classes and structures are exactly the same thing except for default visibility of members and methods. You are asking about 2 unrelated things—whether related information is inside classes or structures does not matter, nor does it matter if it was allocated dynamically or embedded within an encapsulating class/struct. There are combinations of these 2 things suitable for various situations, and there is a time and place for all of these combinations.

It is just common practice to make structures hold “plain old data”, but otherwise there is nothing unique between classes and structures.


The only part of C++ that should be avoided as much as possible is “goto”.
[EDIT]
Damn it Hodgman, beat me to it.
[/EDIT]


L. Spiro

#1L. Spiro

Posted 30 November 2012 - 02:58 AM

dynamically allocated memory in classes vs putting it in structs.

Classes and structures are exactly the same thing except for default visibility of members and methods. You are asking about 2 unrelated things—whether related information is inside classes or structures does not matter, nor does it matter if it was allocated dynamically or embedded within an encapsulating class/struct. There are combinations of these 2 things suitable for various situations, and there is a time and place for all of these combinations.

It is just common practice to make structures hold “plain old data”, but otherwise there is nothing unique between classes and structures.


The only part of C++ that should be avoided as much as possible is “goto”.


L. Spiro

PARTNERS