Skip to content

Commit 9769197

Browse files
committedDec 15, 2017
Local classes inside functions implemented
1 parent baff4ca commit 9769197

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎ClassesInsideFunctions.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
//Implementation of Local classes-Classes defined inside a function
6+
7+
//function prototyping-forward declaration
8+
void getClass();
9+
10+
int main(){
11+
getClass();
12+
return 0;
13+
14+
}
15+
16+
17+
void getClass() {
18+
class Person {
19+
public:
20+
string name;
21+
int age;
22+
void getdetails() {
23+
24+
cout<<"Name: "<<name<<endl<<"Age is :"<<age<<endl;
25+
}
26+
};
27+
28+
//Class object and the members of class can only be used inside the function as it has a local block scope
29+
Person p;
30+
p.name="Anish";
31+
p.age=20;
32+
p.getdetails();
33+
34+
}
35+

0 commit comments

Comments
 (0)
Please sign in to comment.