Results 1 to 5 of 5

Thread: static Object Vs Pointer

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up static Object Vs Pointer

    Hi All,

    I have one doubt in C++. I have seen many places in C++ programs while creating object somewhere static object is used like

    Consider A as Class,

    A a;

    Somewhere we are creating objects as pointers like

    A *a = new A();

    I am having this doubt in this 2 approaches where to use static object and where to use pointer object ?

    Please clear my doubt?
    Thanks,
    Rajesh.S

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: static Object Vs Pointer

    Somebody was wondering the same thing a few days ago...also, I'm not sure its quite correct to refer to objects created on the stack as "static." C++ has a "static" keyword that means something quite different.

    http://www.qtcentre.org/forum/f-gene...ing-13962.html
    Last edited by JimDaniel; 10th June 2008 at 16:28.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: static Object Vs Pointer

    I tend to use the term "full/complete object" (in contrast to pointers that later get assigned a heap based object) for describing stack based objects.

  4. #4
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: static Object Vs Pointer

    Thank you for ur reply. Still i need clear difference between the both.
    Thanks,
    Rajesh.S

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: static Object Vs Pointer

    The only difference is that they are created in different regions of computer memory and heap based objects are persistent in such a way that they don't get deleted automatically as they have no scope. There are no general rules when to use which.

Similar Threads

  1. structs, pointer, static callback function
    By vonCZ in forum General Programming
    Replies: 3
    Last Post: 20th June 2008, 13:53
  2. Replies: 16
    Last Post: 23rd May 2008, 11:12
  3. Saving object pointer
    By MarkoSan in forum General Programming
    Replies: 4
    Last Post: 11th January 2008, 12:53
  4. Virtual static methods alternative :D
    By hickscorp in forum General Programming
    Replies: 8
    Last Post: 4th January 2008, 18:59
  5. Pointer to ActiveX object in QT
    By json84 in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2007, 13:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.