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 b2b9fae

Browse files
Inner/Nested classes
1 parent 9d2f144 commit b2b9fae

File tree

1 file changed

+42
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 16 Friend and static members/Inner_nested_class

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
class Outer
6+
{
7+
public:
8+
int a;
9+
static int b;
10+
11+
void preview()
12+
{
13+
cout<<"i="<<i.x<<endl;
14+
cout<<Outer::b<<endl;
15+
i.show();
16+
}
17+
18+
class Inner
19+
{
20+
public:
21+
int x = 45;
22+
void show()
23+
{
24+
cout<<"Hakunamatata"<<endl;
25+
}
26+
};
27+
28+
Inner i;
29+
};
30+
31+
int Outer::b = 1978; // declare the static variable as a global variable , but only accessible through the scope resolution operator in the target class
32+
33+
int main(void)
34+
{
35+
Outer o;
36+
o.preview();
37+
38+
Outer::Inner i;
39+
i.show();
40+
41+
return 0;
42+
}

0 commit comments

Comments
(0)

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