Jul 27, 2013 at 11:50am UTC
Can any one tell me what is the purpose of having static object of the same class.
for e.g.
class someObj{
public:
static someObj obj;
};
how the compiler treats this object
Jul 27, 2013 at 12:14pm UTC
For example if you want to have only a single object of type someObject and no one could create another object of this type. In this case you can write
1 2 3 4 5 6 7 8 9 10
class someObj
{
private :
someObj() {}
public :
static someObj obj;
};
someObj someObj::obj;
As the constructor is private the client code can not create an object of this type.
Last edited on Jul 27, 2013 at 12:15pm UTC
Jul 27, 2013 at 12:26pm UTC
Last edited on Jul 27, 2013 at 12:47pm UTC