-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cc
34 lines (26 loc) · 845 Bytes
/
main.cc
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
#include <cstdlib>
#include <iostream>
#include <string>
template<class T, typename TFirstNameGeter, typename TLastNameGeter, typename TAgeGeter>
void Print(T person, TFirstNameGeter GetFirstName, TLastNameGeter GetLastName, TAgeGeter GetAge) {
std::cout << person.*GetFirstName << " "
<< person.*GetLastName << ", "
<< person.*GetAge << std::endl;
}
template<class T, int (T::*AgeGetter)>
void PrintAge(T person) {
std::cout << person.*AgeGetter << std::endl;
}
struct Person {
std::string firstName;
std::string lastName;
int age;
};
int main(int argc, char **argv) {
Person a { "Abbas", "Gussenov", 29 };
Print<Person>(a, &Person::firstName, &Person::lastName, &Person::age);
// Abbas Gussenov, 29
PrintAge<Person, &Person::age>(a);
// 29
return EXIT_SUCCESS;
}