the operator of c++

#include <iostream>

class TT
{
    public:
    int a;
    TT(){a=0;}
    TT(int xa){a=xa;}
    TT(const TT& xa){a=xa.a;}

    operator int(){return a;} //hidden convert TT to int
    operator char(){return 48+a;}
    void operator()(){std::cout<<"xyz"<<std::endl;} //functor
};

int main()
{
    TT a;
    TT b(2);
    int ia = a;
    int ib = b;
    char cc = a;
    std::cout<<ia<<std::endl;
    std::cout<<ib<<std::endl;
    std::cout<<cc<<std::endl;
    //std::cout<<a(5)<<std::endl;
    a();
}
by 1957
原文地址:https://www.cnblogs.com/x1957/p/2872023.html