C++ template question

closed account (2E1bM4Gy)
Hello,

In my test.h file,

template <class T>
class B : public A<T> {
public:
// B( const T &x ) : A<T>(x) {}
B<T> * my_method( const T &x );
}

Given the test.h file, how do I declare my_method(const T &x) in test.cpp so that two files can compile together?

I tried following in test.cpp, but it was not working.

#include "test.h"
template <class T>
B<T>*::my_method(const T &x)
{
B<T>* temp_test;
return temp_test;
}

Thank you.


Place the definition in the header file.

See: Why can’t I separate the definition of my templates class from its declaration and put it inside a .cpp file?
https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl
Topic archived. No new replies allowed.