Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d2f144

Browse files
static member data
1 parent 61b3469 commit 9d2f144

File tree

1 file changed

+37
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 16 Friend and static members/Static_members_2

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Student
6+
{
7+
private:
8+
int rollNumber;
9+
string name;
10+
static int admissionNumber;
11+
12+
public:
13+
Student(string n): name(n)
14+
{
15+
admissionNumber++;
16+
rollNumber = admissionNumber;
17+
}
18+
19+
void display()
20+
{
21+
cout<<"Name="<<name<<"\tRollNumber="<<rollNumber<<endl;
22+
}
23+
};
24+
25+
int Student::admissionNumber;
26+
27+
int main(void)
28+
{
29+
Student s1("George");
30+
s1.display();
31+
Student s2("Mara");
32+
s2.display();
33+
Student s3("Sorina");
34+
s3.display();
35+
36+
return 0;
37+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /