#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 . :)

Recommended Answers

A static class member exists on a class level as opposed to non-static class members that exist on an object level. For example, what you can do with s_b but not with b is access it without having an "A" object, as it's not part of an object but of …

Jump to Post

All 2 Replies

A static class member exists on a class level as opposed to non-static class members that exist on an object level. For example, what you can do with s_b but not with b is access it without having an "A" object, as it's not part of an object but of a class. Every object will have it's own "b" though.

A static member is shared between all objects of the class whereas each object of the class contains a copy of the instance member. It's really as simple as that, though the static keyword is heavily used for different purposes in C++.

LearnCpp - Static Members
IBM Reference - Static Members

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.