3

次のコードがあります ( http://ideone.com/6ozZrsからも入手できます):

#include <iostream>

template<class T>
class MyClass{
    public:
        inline MyClass(const T &t);
        template<class C>
        void MyUberFunction(const C &c)
        {
            std::cout<<"My t: "<<m_t<<std::endl;
            std::cout<<"Do uber things with: "<<&c<<std::endl;
        }
    private:
        T m_t;
};

template<class T>
MyClass<T>::MyClass(const T &t):
    m_t(t)
{
}

int main(int argc, char *argv[])
{
    MyClass<int> myInstance(1337);
    myInstance.MyUberFunction("Another type");

    return 0;
}

MyUberFunction メソッドは、そのクラスとは異なる一連のテンプレート パラメーターを受け取ります。クラスコンストラクターで行ったように、宣言と定義を分割するにはどうすればよいですか?

4

1 に答える 1