forked from coder2hacker/Explore-open-source
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnonymous_class.cpp
More file actions
38 lines (33 loc) · 868 Bytes
/
Anonymous_class.cpp
File metadata and controls
38 lines (33 loc) · 868 Bytes
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
// Anonymous Class {Type 1}
#include <iostream>
using namespace std;
typedef class
/*here the name of the class is missing so we can call it
nameless class or anonymous class*/
{
private:
int x;
public:
void get_data()
{
cout<<"\nEnter the value of x: ";
cin>>x;
}
void show_data()
{
cout<<"\nx="<<x;
}
}Number;
int main()
{
Number N1;
/*here N1 is object of a nameless class.
Number is used as an alternative name for the nameless class is achived by
typedef. typedef is used to rename the data type name.
here we have defined a class using typedef class. No class name is present here,
but at the end of the class declaration we have renamed the nameless class.
*/
N1.get_data();
N1.show_data();
return 0;
}