Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c++ templated methods

Name: Anonymous 2007-10-07 1:33

How to write implementation of method foo?


template <class T>
class Foo
{
public:
    Foo(void){}
    ~Foo(void){}
    template<class T1> void test(T1 a);
};

Name: Anonymous 2007-10-07 8:36

>>10
A surprise awaits you:

Put this code into .h file:
template < class T >
struct Foo {
        template < class T1 >
        void bar( T1 arg );
};

,and this code into .cpp file:
template < class T >
template < class T1 >
void Foo<T>::bar( T1 arg ) {
        std::cout << arg << std::endl;
}


And it's not going to work! With templates you can't have separate compilation. Hooray for c++! (and export isn't implemented anywhere so shut up, stroustrup)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List