8000 class Object typecast · DhirajGadekar/Cpp_programming@b87aedc · GitHub
[go: up one dir, main page]

Skip to content

Commit b87aedc

Browse files
committed
class Object typecast
1 parent 0fa51de commit b87aedc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<iostream>
2+
3+
class Demo {
4+
5+
int x = 10;
6+
float y = 12.5f;
7+
public:
8+
Demo() {
9+
10+
}
11+
Demo(int x, float y) {
12+
13+
this->x = x;
14+
this->y = y;
15+
}
16+
void getData() {
17+
18+
std::cout << x << std::endl;
19+
std::cout << (float)y << std::endl;
20+
}
21+
22+
};
23+
int main() {
24+
25+
Demo obj1;
26+
obj1.getData();
27+
Demo obj = (Demo){40, 45.6f};
28+
obj.getData();
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)
0