template_constructor_function

#include <iostream>
using namespace std;

template <class T>
class MyClass{
    public:
        template<class U>
        MyClass(const MyClass<U>& x)
        {
            cout<<"MyClass(const MyClass<U>& x)"<<endl;
        }

        MyClass(const MyClass<T>& x)
        {
            cout<<"MyClass(const MyClass<T>& x)"<<endl;
        }

        MyClass()
        {
            cout<<"MyClass()"<<endl;
        }
};

void main()
{
    MyClass<double> xd;
    cout<<"========================"<<endl;
    MyClass<int> xi(xd);
    cout<<"========================"<<endl;
    MyClass<int> yi(xi);
/*
MyClass()
========================
MyClass(const MyClass<U>& x)
========================
MyClass(const MyClass<T>& x)
Press any key to continue    
*/
}

 

posted @ 2017-02-23 18:25  sky20080101  阅读(183)  评论(0编辑  收藏  举报