Skip to content

Instantly share code, notes, and snippets.

@congdanhqx-zz
Created September 8, 2013 12:01
Show Gist options
  • Save congdanhqx-zz/6484222 to your computer and use it in GitHub Desktop.
Save congdanhqx-zz/6484222 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
template <class T>
int get_age(T obj) {
return obj.age;
}
class Person {
public:
int age;
};
class Tree {
public:
int age;
};
int main() {
Person p;
Tree t;
p.age = 10;
t.age = 1000;
cout << get_age(p) << endl;
cout << get_age(t) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment