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. creating limited objects

creating limited objects

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 7 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.
  • P Offline
    P Offline
    p_1960
    wrote on last edited by
    #1

    Hi, if i want to create only 3 objects how can i restrict the class to do the same...

    W I R L D 5 Replies Last reply
    0
    • P p_1960

      Hi, if i want to create only 3 objects how can i restrict the class to do the same...

      W Offline
      W Offline
      wangningyu
      wrote on last edited by
      #2

      // Create only 3 objects in class demo.

      #include

      static int nCount = 0;

      class Demo
      {
      public:
      Demo()
      {
      nCount++;
      }
      };

      bool IsMax()
      {
      if(nCount>3)
      return true;
      else
      return false;
      }

      int main()
      {
      // here is 4 objects.
      Demo d1,d2,d3,d4;
      if(IsMax())
      {
      cout<<"error"<

      C 1 Reply Last reply
      0
      • P p_1960

        Hi, if i want to create only 3 objects how can i restrict the class to do the same...

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        I've never even heard of a "tripleton" class, and we have two different people wanting it within hours of each other? http://www.codeproject.com/Messages/3229571/Class-Object.aspx[^] Maybe you should speak with your classmate / colleague and collaborate. His question has answers too. Iain.

        I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]

        1 Reply Last reply
        0
        • P p_1960

          Hi, if i want to create only 3 objects how can i restrict the class to do the same...

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          If you don't stop using multiple logins to ask the same stupid queries, I'll take it to the admin to have all your logins banned. I remember warning you once already. :|

          It is a crappy thing, but it's life -^ Carlo Pallini

          C 1 Reply Last reply
          0
          • P p_1960

            Hi, if i want to create only 3 objects how can i restrict the class to do the same...

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

            p_1960 wrote:

            if i want to create only 3 objects how can i restrict the class to do the same...

            You could start by reading the suggestions that people offer, and trying to implement them in your program.

            modified on Sunday, October 11, 2009 3:33 PM

            1 Reply Last reply
            0
            • W wangningyu

              // Create only 3 objects in class demo.

              #include

              static int nCount = 0;

              class Demo
              {
              public:
              Demo()
              {
              nCount++;
              }
              };

              bool IsMax()
              {
              if(nCount>3)
              return true;
              else
              return false;
              }

              int main()
              {
              // here is 4 objects.
              Demo d1,d2,d3,d4;
              if(IsMax())
              {
              cout<<"error"<

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

              Why don't you keep your wonderful techniques secret? :)

              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
              • R Rajesh R Subramanian

                If you don't stop using multiple logins to ask the same stupid queries, I'll take it to the admin to have all your logins banned. I remember warning you once already. :|

                It is a crappy thing, but it's life -^ Carlo Pallini

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

                Rajesh R Subramanian wrote:

                If you don't stop using multiple logins

                He's asking for Singleton-like patters just for limiting his logins... :-D

                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
                • P p_1960

                  Hi, if i want to create only 3 objects how can i restrict the class to do the same...

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  p_1960 wrote:

                  ...how can i restrict the class to do the same...

                  By reading here.

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  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