jinyedge's note
{http://www.jinyedge.pe.kr}
Hi, this is jinyedge. I'm a software developer.
I hope you can find some useful information
in my homepage.
jinyedge at gmail.com
Since 2001.12.05
|
|
| Subj: C++, Function template, operator overloading. |
|
|
Mtime: 2009-12-07 20:15:28 |
|
|
#include <iostream>
using namespace std;
//------------------------------------------------------------------------
class Man{
private:
string name;
int age;
public:
Man(string _name, int _age) : name(_name), age(_age){}
friend ostream& operator << (ostream& os, const Man& m);
};
//------------------------------------------------------------------------
ostream& operator << (ostream& os, const Man& m){
cout << "----------------------------" << endl;
cout << "name: " << m.name << endl;
cout << "age: " << m.age << endl;
cout << "----------------------------" << endl;
return os;
}
//------------------------------------------------------------------------
template<class T> void test_func(T x){
cout << "x = "<< x << endl;
}
//------------------------------------------------------------------------
int main(){
test_func(1);
test_func("12345");
Man m = Man("kman", 28);
cout << m;
return 0;
}
|
|
|
|
|