同様の質問がSOですでに何度も行われています。
しかしとにかく...
まず、構文エラーが発生しました。
それ以外の
#ifndef ........
#define .....
template <class typename>
class abcBaseClass:public abcDerivedClass{
public:
typename getvalue(char*);
};
#endif
このようなものでなければなりません。
#ifndef ........
#define .....
template <typename T>
class abcBaseClass:public abcDerivedClass{
public:
T getvalue(char*);
};
// Definition follow in this file!
// For reasons or work-arounds, read below.
#endif
また、テンプレート宣言と定義の両方を同じファイルに入れる必要があります。1つの例外は、そのテンプレートを、テンプレート定義があるソースファイルのあるタイプにインスタンス化する場合です。
このようなもの。
#include "this_template.h"
template <typename T>
// all sorts of definitions...
// Explicit instantiate this template!!!!
template class abcBaseClass<Your_Type_Goes_Here>;
このアプローチの根本的な欠陥は、プログラム内の他の場所では、このソースファイルで明示的にインスタンス化したタイプしか使用できないことです。このテンプレートを他のタイプでインスタンス化しようとすると、リンカは一致する定義が見つからないと文句を言います。
テンプレートが一般的であり、テンプレートクラスの定義を別の場所に置くことを主張する場合。定義を別のヘッダーファイルに入れて、次のように呼び出してインクルードすることがthis_template_impl.h
できthis_template.h
ますthis_template_impl.h
次に、ソースファイルに、の代わりに次の#include "this_template.h"
ように記述します。#include "this_template_impl.h