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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what is a static class

what is a static class

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
20 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.
  • T toxcct

    Cedric Moonen wrote:

    Yes, you can declare a class static like any other variable

    actually, you're not declaring the class static but the instance of the class...


    TOXCCT >>> GEII power

    [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

    C Offline
    C Offline
    Cedric Moonen
    wrote on last edited by
    #5

    Yes, my post has already been modified :-D. It's friday afternoon so my english skills tend to decrease :doh:


    Cédric Moonen Software developper
    Charting control

    1 Reply Last reply
    0
    • C Cedric Moonen

      kumar_windows wrote:

      is there any thing like static class in c++

      What do you mean exactly ? Can you be more explicit and explain what you want to do exactly ? Yes, you can declare a class static like any other variable but I don't know if this is what you are looking for.


      Cédric Moonen Software developper
      Charting control -- modified at 9:43 Friday 12th May, 2006 Sorry, not very clear :~ . As toxxct said (and what I meant by saying that) is declaring an instance of a class static, not the class itself

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #6

      Cedric Moonen wrote:

      Sorry, not very clear . As toxxct said

      damn, toxcct, not toxxct ;P think to "toxicity" if that can help... anyway, ok, friday afternoon... hehehe


      TOXCCT >>> GEII power

      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

      C 1 Reply Last reply
      0
      • T toxcct

        Cedric Moonen wrote:

        Sorry, not very clear . As toxxct said

        damn, toxcct, not toxxct ;P think to "toxicity" if that can help... anyway, ok, friday afternoon... hehehe


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #7

        Do you think it's easy not to make mistakes while typing with your nose ? :rolleyes:


        Cédric Moonen Software developper
        Charting control

        T T 2 Replies Last reply
        0
        • C Cedric Moonen

          Do you think it's easy not to make mistakes while typing with your nose ? :rolleyes:


          Cédric Moonen Software developper
          Charting control

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #8

          arg, you're right, those letters are too close :doh:


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          1 Reply Last reply
          0
          • C Cedric Moonen

            Do you think it's easy not to make mistakes while typing with your nose ? :rolleyes:


            Cédric Moonen Software developper
            Charting control

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #9

            Cedric Moonen wrote:

            while typing with your nose ?

            Again Nose:)

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV

            1 Reply Last reply
            0
            • K kumar_mk

              is there any thing like static class in c++ thank u kk.

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #10

              kumar_windows wrote:

              is there any thing like static class in c++

              Are you looking something like SingleTon Classes[^]?

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              K 1 Reply Last reply
              0
              • T toxcct

                static class, no. static instance of a class yes. please explain where you heard this, and what you want to be detailed...


                TOXCCT >>> GEII power

                [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                K Offline
                K Offline
                kumar_mk
                wrote on last edited by
                #11

                hello toxcct, it was asked to me in an interview, u r saying we have a static class , like static class A{ ----- }; and if i create an object for it what happens??? kk

                T T 2 Replies Last reply
                0
                • C Cedric Moonen

                  kumar_windows wrote:

                  is there any thing like static class in c++

                  What do you mean exactly ? Can you be more explicit and explain what you want to do exactly ? Yes, you can declare a class static like any other variable but I don't know if this is what you are looking for.


                  Cédric Moonen Software developper
                  Charting control -- modified at 9:43 Friday 12th May, 2006 Sorry, not very clear :~ . As toxxct said (and what I meant by saying that) is declaring an instance of a class static, not the class itself

                  K Offline
                  K Offline
                  kumar_mk
                  wrote on last edited by
                  #12

                  hello cedric, it was an interview question, u mean to say i can declare a class as static like static class A{----}; what is its purpose, please elaborate on single instance of a class, u mean when i create an object for this class thanks kk

                  1 Reply Last reply
                  0
                  • T ThatsAlok

                    kumar_windows wrote:

                    is there any thing like static class in c++

                    Are you looking something like SingleTon Classes[^]?

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    cheers, Alok Gupta VC Forum Q&A :- I/ IV

                    K Offline
                    K Offline
                    kumar_mk
                    wrote on last edited by
                    #13

                    hi alok, no not a singleton class, it was an interview question abt the static class, do we have it just like a static member variable and static function, wat is its significance/purpose?? can i create an object for this static class?? wat happens? thank u, kk

                    1 Reply Last reply
                    0
                    • K kumar_mk

                      hello toxcct, it was asked to me in an interview, u r saying we have a static class , like static class A{ ----- }; and if i create an object for it what happens??? kk

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #14

                      dude !!! didn't you read what i said, or didn't you understand ? when i say you cannot define a class as static, it means that you CANNOT define a class like you do :

                      static class CFoo { // No !!! compilation error
                      // You cannot apply the static keyword to a type definition
                      //...

                      };

                      what i said however is that you are allowed to declare an instance of a class as static, that means a variable which type is a user-defined type :

                      #include "Foo.h"

                      static CFoo foo; // Allowed ! foo variable of type CFoo is static

                      now, what don't you understand ? you'd certainly google the internet or even better, search a good C++ book for static concept...


                      TOXCCT >>> GEII power

                      [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                      1 Reply Last reply
                      0
                      • K kumar_mk

                        is there any thing like static class in c++ thank u kk.

                        M Offline
                        M Offline
                        Maxwell Chen
                        wrote on last edited by
                        #15

                        The code snipet below demonstrates the variable instance obj to be static not the type Type, even though it would be confusing you.

                        #include <iostream>

                        int main()
                        {
                        static class Type
                        {
                        public:
                        void Hello() { std::cout << "Type::Hello() \n"; }
                        } obj;
                        obj.Hello();
                        return 0;
                        }

                        Which is equivelent to:

                        #include <iostream>

                        int main()
                        {
                        class Type
                        {
                        public:
                        void Hello() { std::cout << "Type::Hello() \n"; }
                        };
                        static Type obj;
                        obj.Hello();
                        return 0;
                        }


                        Maxwell Chen

                        T 1 Reply Last reply
                        0
                        • M Maxwell Chen

                          The code snipet below demonstrates the variable instance obj to be static not the type Type, even though it would be confusing you.

                          #include <iostream>

                          int main()
                          {
                          static class Type
                          {
                          public:
                          void Hello() { std::cout << "Type::Hello() \n"; }
                          } obj;
                          obj.Hello();
                          return 0;
                          }

                          Which is equivelent to:

                          #include <iostream>

                          int main()
                          {
                          class Type
                          {
                          public:
                          void Hello() { std::cout << "Type::Hello() \n"; }
                          };
                          static Type obj;
                          obj.Hello();
                          return 0;
                          }


                          Maxwell Chen

                          T Offline
                          T Offline
                          toxcct
                          wrote on last edited by
                          #16

                          i hesitated to show off this example, but finally didn't, thinking it would confuse most beginners around. by the way, it is perfectly legal to do so, as we declare a variable with the type definition inlined...


                          TOXCCT >>> GEII power

                          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                          M 1 Reply Last reply
                          0
                          • T toxcct

                            i hesitated to show off this example, but finally didn't, thinking it would confuse most beginners around. by the way, it is perfectly legal to do so, as we declare a variable with the type definition inlined...


                            TOXCCT >>> GEII power

                            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                            M Offline
                            M Offline
                            Maxwell Chen
                            wrote on last edited by
                            #17

                            And a further example to demonstrate that the member variables are not shared among individual static instances.

                            #include <iostream>

                            static class Type
                            {
                            int v;
                            public:
                            void Hello() {
                            std::cout << "Type::Hello() \nv = " << v << " \n";
                            }
                            void Hello(int n) {
                            v = n;
                            std::cout << "Type::Hello(" << v << ") \n";
                            }
                            } g_obj, g_objx;

                            int main()
                            {
                            std::cout << "g_obj \n";
                            g_obj.Hello(3);
                            g_obj.Hello();
                            std::cout << "g_objx \n";
                            g_objx.Hello();
                            return 0;
                            }

                            The output goes to:

                            g_obj
                            Type::Hello(3)
                            Type::Hello()
                            v = 3
                            g_objx
                            Type::Hello()
                            v = 0


                            Maxwell Chen

                            1 Reply Last reply
                            0
                            • K kumar_mk

                              is there any thing like static class in c++ thank u kk.

                              S Offline
                              S Offline
                              Stephen Hewitt
                              wrote on last edited by
                              #18

                              C# has the concept of a static class: a static class is a class that contains only static members and instances can't be created with the new keyword. C++ has no such concept; although you can create classes with only static members you do so explictly and the compiler will not stop you from adding a non-static member. Steve

                              1 Reply Last reply
                              0
                              • K kumar_mk

                                hello toxcct, it was asked to me in an interview, u r saying we have a static class , like static class A{ ----- }; and if i create an object for it what happens??? kk

                                T Offline
                                T Offline
                                ThatsAlok
                                wrote on last edited by
                                #19

                                kumar_windows wrote:

                                u r saying we have a static class , likestatic class A{ ----- };and if i create an object for it what happens???

                                Dude There is nothing like Static class, as class doesnot have any address till is object is created, so how can you make anything static which doesn't exist till it object is created

                                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                                cheers, Alok Gupta VC Forum Q&A :- I/ IV

                                1 Reply Last reply
                                0
                                • K kumar_mk

                                  is there any thing like static class in c++ thank u kk.

                                  N Offline
                                  N Offline
                                  Nemanja Trifunovic
                                  wrote on last edited by
                                  #20

                                  kumar_windows wrote:

                                  is there any thing like static class in c++

                                  No.


                                  My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

                                  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