-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatic_Member_function_and_Variable_2.cpp
More file actions
42 lines (36 loc) · 1.1 KB
/
Copy pathStatic_Member_function_and_Variable_2.cpp
File metadata and controls
42 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//author: jaydtatpatel
//static member function and variable
/*
static member function can not be declare as virtual and friend function.
static member function can not be declared const, volatile, or const volatile.
static member function can not be same as other function name
*/
#include <iostream>
using namespace std;
class class_A
{
int x;
public:
class_A() { cout << "\nclass_A's Constructor Called " << endl; }
};
class class_B
{
static class_A a;
public:
class_B() { cout << "\nclass_B's Constructor Called " << endl; }
static class_A getA()
{ return a; }
};
class_A class_B::a; // defination of a (so constri=uctor will execute of class_a when program starts)
int main()
{
cout<<"\n1.------------\n";
class_A a = class_B::getA();
cout<<"\n2.------------\n";
class_B b1, b2, b3;
cout<<"\n3.------------\n";
class_A a1;
cout<<"\n4.------------\n";
class_A a2 = b1.getA();
return 0;
}