#include <iostream>
using namespace std;
//template<class T> class Test;
template <typename T>
class A{
public:
// friend ostream &operator <<(ostream &out,A&obj){
// out<<obj.a<<endl;
// return out;
// }
// friend ostream &operator << <T>(ostream &out,const A<T>&);
friend void friendPrint();
template<typename C>//这个参数的类型和 T 不同
friend void friendPrint2(A<C> &a);
// friend void frindPrint3<T>(T u);
// friend void display(A<T> &t);
A operator+(A &c2){
A tmp(a+c2.a);
return tmp;
}
A(T a){
this->a = a;
}
public:
void printA(){
cout<<"a :"<<a<<endl;
}
int getA(){
return a;
}
private:
T a;
};
template <typename T>
ostream &operator <<(ostream &out, A<T>&obj){
out<<obj.getA();
return out;
}
//template<typename T>
void friendPrint(){
cout<<"----"<<1111111<<endl;
}
template <typename C>
void friendPrint2(A<C> &mya){
cout<<mya.a<<endl;
}
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
A<int> a1(10);
A<int> a2(20);
A<int> a3 = a1+a2;
// a1.printA();
cout<<a3<<endl;
friendPrint();
//friendPrint(a3);
friendPrint2(a3);
return 0;
}
网友评论