Max no of objects in c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chetanamale
    New Member
    • Sep 2007
    • 7

    Max no of objects in c++

    Hi :

    I have two doubts :

    1) Whats is the maximum no of objects we can define of the same class ?

    2)If we have created instance of a class in particular method belong to the same

    class or its friend class ( as mentioned below), what is the scope of this

    object ?? will it get destroyed once we return from the method ??


    void method x()

    {

    car c ;

    }


    thanks.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    1. You are limitied only by the available memory on the platform

    2. The object has function scope, is created on the stack(on most platforms) and is deleted automatically at the end of the function. However some people would question putting an object on the stack like this and would suggest allocating the object from the heap. However this is rally a platform issue, if you platform has a large stack but a small heap then allocating from the stack is better, conversely if your platform has a small stack and a large heap then allocating from the heap is better, if there are about the same it makes little difference.

    If you do allocate from the heap then you will need to delete the object explicitly, you can get round this requirement by using the smart pointer template which is explained in the C++ articles.

    Comment

    Working...