File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < string>
3
+ #include < tuple>
4
+
5
+ using namespace std ;
6
+
7
+
8
+ class Person
9
+ {
10
+ public:
11
+ static Person newPerson (string name, int age) {
12
+ return {name, age};
13
+ }
14
+ void sayHello () {
15
+ cout << " Hello, my name is " << this ->name << " and I am " << this ->age << " y.o." << endl;
16
+ }
17
+ tuple<string, int > getData () {
18
+ return make_tuple (name, age);
19
+ }
20
+ private:
21
+ string name;
22
+ int age;
23
+ Person (string name, int age)
24
+ : name(name), age(age)
25
+ {}
26
+ };
27
+
28
+
29
+ int main ()
30
+ {
31
+ Person diman = Person::newPerson (" Zizou" , 47 );
32
+ Person *str_ptr = &diman;
33
+
34
+ cout << " Hello, my name is " << get<0 >(str_ptr->getData ()) << " and I am " << get<1 >(str_ptr->getData ()) << " y.o." << endl;
35
+
36
+ // deallocate memory used by str_ptr in Heap memomry
37
+ //
38
+ delete str_ptr;
39
+
40
+ return 0 ;
41
+ }
42
+
43
+
You can’t perform that action at this time.
0 commit comments