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. using container class for c++ class objects

using container class for c++ class objects

Scheduled Pinned Locked Moved C / C++ / MFC
c++dockertutorial
8 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.
  • H Offline
    H Offline
    hawk23reddy
    wrote on last edited by
    #1

    hi, i know how to count number of objects created for class using static variable, but i came to know that there is other way i.e using container class, can any one specify how it is and if any code it will be helpfull or even links are accepted.. iam attending interviews these questions asked for me.. so please helpme.. ( i answered this but dont know how to write code for this).

    C B _ 3 Replies Last reply
    0
    • H hawk23reddy

      hi, i know how to count number of objects created for class using static variable, but i came to know that there is other way i.e using container class, can any one specify how it is and if any code it will be helpfull or even links are accepted.. iam attending interviews these questions asked for me.. so please helpme.. ( i answered this but dont know how to write code for this).

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Have you heard about Google [^]? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      H 1 Reply Last reply
      0
      • H hawk23reddy

        hi, i know how to count number of objects created for class using static variable, but i came to know that there is other way i.e using container class, can any one specify how it is and if any code it will be helpfull or even links are accepted.. iam attending interviews these questions asked for me.. so please helpme.. ( i answered this but dont know how to write code for this).

        B Offline
        B Offline
        BadKarma
        wrote on last edited by
        #3

        Hi, a container or collection holds/stores a number of objects. The STL library provides a number of containters.

        #include <vector>
        
        class MyObject
        {
        public:
          MyObject() {}
          
          void DoSomething() {}
        };
        
        void main()
        {
          std::vector<MyObject*> vecList;
        
          vecList.push_back(new MyObject);
          vecList.push_back(new MyObject);
          vecList.push_back(new MyObject);
        
          // count will hold the number of objects
          int count = vecList.size();
        }
        

        Learn from the mistakes of others, you may not live long enough to make them all yourself.

        1 Reply Last reply
        0
        • C CPallini

          Have you heard about Google [^]? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          H Offline
          H Offline
          hawk23reddy
          wrote on last edited by
          #4

          hello pallini :rose:, i know google is there then y is code project is there c i can even post here right which i fell is the best so never try to answer like this is u dont feel of answering then please never ever try. ( i belive in code project and myself and also internet so no need of ur answers any more)hope u got what i mean. then if google is there then y code project is needed ? :mad:

          C 1 Reply Last reply
          0
          • H hawk23reddy

            hi, i know how to count number of objects created for class using static variable, but i came to know that there is other way i.e using container class, can any one specify how it is and if any code it will be helpfull or even links are accepted.. iam attending interviews these questions asked for me.. so please helpme.. ( i answered this but dont know how to write code for this).

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            Create a static int variable inside the class. Increment it in the constructor and decrement it in the destructor.

            «_Superman_» I love work. It gives me something to do between weekends.

            1 Reply Last reply
            0
            • H hawk23reddy

              hello pallini :rose:, i know google is there then y is code project is there c i can even post here right which i fell is the best so never try to answer like this is u dont feel of answering then please never ever try. ( i belive in code project and myself and also internet so no need of ur answers any more)hope u got what i mean. then if google is there then y code project is needed ? :mad:

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              hawk23reddy wrote:

              so never try to answer like this is u dont feel of answering then please never ever try.

              And why? Is it the "hawk23reddy's rule"? Do you really think I will follow it?

              hawk23reddy wrote:

              i belive in code project and myself and also internet so no need of ur answers any more

              I'm happy about.

              hawk23reddy wrote:

              hope u got what i mean.

              Possibly, you know, I'm a "rather dull child"... :rolleyes:

              hawk23reddy wrote:

              then if google is there then y code project is needed ?

              Both are useful. And they are more useful if you post the right question to the right one, I suppose. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              H 1 Reply Last reply
              0
              • C CPallini

                hawk23reddy wrote:

                so never try to answer like this is u dont feel of answering then please never ever try.

                And why? Is it the "hawk23reddy's rule"? Do you really think I will follow it?

                hawk23reddy wrote:

                i belive in code project and myself and also internet so no need of ur answers any more

                I'm happy about.

                hawk23reddy wrote:

                hope u got what i mean.

                Possibly, you know, I'm a "rather dull child"... :rolleyes:

                hawk23reddy wrote:

                then if google is there then y code project is needed ?

                Both are useful. And they are more useful if you post the right question to the right one, I suppose. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                H Offline
                H Offline
                hawk23reddy
                wrote on last edited by
                #7

                ;) :doh: :sigh: :doh: thankx,, what to do myan iam poor in lang...

                C 1 Reply Last reply
                0
                • H hawk23reddy

                  ;) :doh: :sigh: :doh: thankx,, what to do myan iam poor in lang...

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  hawk23reddy wrote:

                  thankx,, what to do myan iam poor in lang...

                  I don't know. On the other hand, I'm pretty sure that your previous post was a bit rude. Anyway I don't care. :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  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