CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2012
    Posts
    17

    Importance of static object in a class and how they are different from general object

    #include "B.h"
    class A
    {
    public :
    A()
    {
    s_b = new B();
    b = new B();
    }
    static B s_b ;
    B b ;
    };
    #include<iostream>
    using namespace std ;
    #include "A.h"
    int main()
    {
    cout<<"hello";
    }
    In my project i have seen static object as above . But not able to know what is the exact use of it and how they are different from general object . Please help me in finding out What all the things i can do with s_b which is not being done by b .

    Thanks in advance .

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Importance of static object in a class and how they are different from general ob

    Did you try to compile this?

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Importance of static object in a class and how they are different from general ob

    a static class member and a global object are pretty much the same from a generated code p.o.v.

    from a C++ p.o.v., one is a class member, and the other is not (well duh)
    meaning, you can make the class member public access, protected access of private access.

    the global object will be public access either only for the module (.cpp file) it's declared in, or it will be public access for all the modules in compilation.

    Short story: the only difference is that the static member is encapculated where the other (global) is not.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured