Class ABC
{
int a;
int b;
static int c;
}ABC;
ABC::c=10;
void fun()
{
cout<<" Value of a is "<<ABC.a<<endl;
}
No need to write logic to handle singleton, this was you'll have only one object in the program ABC.
Example:
#include<stdio.h>
class singleton
{
public:
static int value;
void print()
{
printf("hello %d\n",value);
}
int a;
}singleton;
singleton::value=5;
int main()
{
// singleton s; #cannot define a new instant like this anymore.
singleton.a=5;
printf("a=%d\n",singleton.a);
singleton.print();
return 0;
}
{
int a;
int b;
static int c;
}ABC;
ABC::c=10;
void fun()
{
cout<<" Value of a is "<<ABC.a<<endl;
}
No need to write logic to handle singleton, this was you'll have only one object in the program ABC.
Example:
#include<stdio.h>
class singleton
{
public:
static int value;
void print()
{
printf("hello %d\n",value);
}
int a;
}singleton;
singleton::value=5;
int main()
{
// singleton s; #cannot define a new instant like this anymore.
singleton.a=5;
printf("a=%d\n",singleton.a);
singleton.print();
return 0;
}
Good one. Please remove the commented code, so that newebies will not get confused.
ReplyDeleteThanks Roopesh. I removed the comments.
Delete