Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Object Creation of an class?

Object Creation of an class?

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mathan_CodeProject
    wrote on last edited by
    #1

    Hi, I am developing an app for mobile using C++, I am calling DownloadManager from Homectrl.CPP, Then came to my mind, which will one will efficient and object will be nullified. What is the exact difference between DownloadManager objDownloadManager; and DownloadManager *objDownloadManager; Which one will be used? Some good insight will be appreciated.

    L L M 3 Replies Last reply
    0
    • M Mathan_CodeProject

      Hi, I am developing an app for mobile using C++, I am calling DownloadManager from Homectrl.CPP, Then came to my mind, which will one will efficient and object will be nullified. What is the exact difference between DownloadManager objDownloadManager; and DownloadManager *objDownloadManager; Which one will be used? Some good insight will be appreciated.

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      It makes no difference whether you are dealing with an object or a standard item like an int, float or double. This form you have created the item type ... these all do the same

      int i; // You created an integer type called i
      double d; // You created a double called d
      DownloadManager objDownloadManager; // You created a DownloadManager called objDownloadManager

      This form you have created a POINTER TO THE ITEM ... it's most likely just 4 bytes (assuming 32bit compilation). As we haven't set them to anything they are effectively undefined and could be pointing anywhere.

      int* i; // You created a pointer to an integer type called i
      double* d; // You created a pointer to a double type called d
      DownloadManager* objDownloadManager; // You created a pointer to a DownloadManager type called objDownloadManager

      So they are vastly different and not something you should ever be confused about .. NOT EVER. So if you like the second form is like the address to your house, the first form is your ACTUAL PHYSICAL house. What you are doing is telling me that if I write text for the address of a house I can live in the text because it's the same thing as a physical house and it's confusing to you. You use the pointer form for the same reason you use a written address for you house. Its a bit tiresome and hard to carry the whole house around just so people can send you mail. The alternative reason might be because your house hasn't yet been built to carry around :-)

      In vino veritas

      M 1 Reply Last reply
      0
      • M Mathan_CodeProject

        Hi, I am developing an app for mobile using C++, I am calling DownloadManager from Homectrl.CPP, Then came to my mind, which will one will efficient and object will be nullified. What is the exact difference between DownloadManager objDownloadManager; and DownloadManager *objDownloadManager; Which one will be used? Some good insight will be appreciated.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi, Some practical thinking: Case 1. You declare 'DownloadManager' as a member of another class: The object declaration (DownloadManager objDownloadManager) means, objDownloadManager has the same life time of your parent (the class in which you have declared it) class. But, pointer member means objDownloadManager will live even if his parent die. Case 2. You declare 'DownloadManager' in a function: The object gets destructed just after function scope. But the pointer declaration, can live until you delete it either inside or outside the function scope (provided you keep the address). Thats all I know.

        M 1 Reply Last reply
        0
        • M Mathan_CodeProject

          Hi, I am developing an app for mobile using C++, I am calling DownloadManager from Homectrl.CPP, Then came to my mind, which will one will efficient and object will be nullified. What is the exact difference between DownloadManager objDownloadManager; and DownloadManager *objDownloadManager; Which one will be used? Some good insight will be appreciated.

          M Offline
          M Offline
          Midi_Mick
          wrote on last edited by
          #4

          One other point to remember - if you declare a pointer to the object (the second declaration), you need to explicitly call the constructor and destructor. When declaring it as an instance (first declaration), the constructor is called automatically at the point of the declaration, and the destructor is called when it goes out of scope.

          Cheers, Mick ------------------------------------------------ It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.

          M 1 Reply Last reply
          0
          • M Midi_Mick

            One other point to remember - if you declare a pointer to the object (the second declaration), you need to explicitly call the constructor and destructor. When declaring it as an instance (first declaration), the constructor is called automatically at the point of the declaration, and the destructor is called when it goes out of scope.

            Cheers, Mick ------------------------------------------------ It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.

            M Offline
            M Offline
            Mathan_CodeProject
            wrote on last edited by
            #5

            Thanks Mick

            1 Reply Last reply
            0
            • L Lost User

              Hi, Some practical thinking: Case 1. You declare 'DownloadManager' as a member of another class: The object declaration (DownloadManager objDownloadManager) means, objDownloadManager has the same life time of your parent (the class in which you have declared it) class. But, pointer member means objDownloadManager will live even if his parent die. Case 2. You declare 'DownloadManager' in a function: The object gets destructed just after function scope. But the pointer declaration, can live until you delete it either inside or outside the function scope (provided you keep the address). Thats all I know.

              M Offline
              M Offline
              Mathan_CodeProject
              wrote on last edited by
              #6

              Thanks Krishna Kumar

              1 Reply Last reply
              0
              • L leon de boer

                It makes no difference whether you are dealing with an object or a standard item like an int, float or double. This form you have created the item type ... these all do the same

                int i; // You created an integer type called i
                double d; // You created a double called d
                DownloadManager objDownloadManager; // You created a DownloadManager called objDownloadManager

                This form you have created a POINTER TO THE ITEM ... it's most likely just 4 bytes (assuming 32bit compilation). As we haven't set them to anything they are effectively undefined and could be pointing anywhere.

                int* i; // You created a pointer to an integer type called i
                double* d; // You created a pointer to a double type called d
                DownloadManager* objDownloadManager; // You created a pointer to a DownloadManager type called objDownloadManager

                So they are vastly different and not something you should ever be confused about .. NOT EVER. So if you like the second form is like the address to your house, the first form is your ACTUAL PHYSICAL house. What you are doing is telling me that if I write text for the address of a house I can live in the text because it's the same thing as a physical house and it's confusing to you. You use the pointer form for the same reason you use a written address for you house. Its a bit tiresome and hard to carry the whole house around just so people can send you mail. The alternative reason might be because your house hasn't yet been built to carry around :-)

                In vino veritas

                M Offline
                M Offline
                Mathan_CodeProject
                wrote on last edited by
                #7

                Thanks In vino veritas.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups