C++类模板友元函数和操作符<<重载实例

#include 
using namespace std;

//template class Test;


template 
class A{
public:
    
//    friend ostream &operator <<(ostream &out,A&obj){
//        out<(ostream &out,const A&);

    friend void friendPrint();
    template//这个参数的类型和 T 不同
    friend void friendPrint2(A &a);
    
//    friend void frindPrint3(T u);
   // friend void display(A &t);
    A operator+(A &c2){
        A tmp(a+c2.a);
        return tmp;
    }
    A(T a){
        this->a = a;
    }
public:

    void printA(){
        cout<<"a :"<
ostream &operator <<(ostream &out, A&obj){
    out<
void friendPrint(){
    cout<<"----"<<1111111<
void friendPrint2(A &mya){
    
    cout< a1(10);
    A a2(20);
    A a3 = a1+a2;
  //  a1.printA();
    cout<

你可能感兴趣的:(C++类模板友元函数和操作符<<重载实例)