0

Possible Duplicate:
Heap vs Stack allocation

If I have the following class definition

class Student
{
string UniversityId;
string firstname;
string lastname;
};

What are the advantages and disadvantges of creating the Student Object on the stack or on the heap.

Community
  • 1
  • 1
programmer
  • 878
  • 5
  • 8
  • There is no such thing as "stack" or a "heap" in the language C++. What are you talking/worrying about? Perhaps you mean automatic vs. dynamic storage? – Kerrek SB Aug 08 '11 at 10:31
  • I don't think http://stackoverflow.com/questions/6713637/heap-vs-stack-allocation is explaining when should the object be allocated on the stack or on the heap? – programmer Aug 08 '11 at 10:35
  • There is a concept of heap memory or stack memory even in c++.. – programmer Aug 08 '11 at 10:36
  • I think [this link](http://stackoverflow.com/questions/3161991/when-should-i-allocate-on-the-heap-c) will help answering your question. – iammilind Aug 08 '11 at 11:02

1 Answers1

0

Use automatic variables ('the stack') until explicit need for using free store ('the heap') arises.

Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224