テンプレートクラスの分割コンパイル

注意 template<class T>は各宣言•定義毎に書く!
hoge.hpp
#ifndef __TEMPLATE_HPP__
#define __TEMPLATE_HPP__

template <class T>
class Hoge {
private:
  T val;
public:
  Hoge( T _val );
  void show();
};

#include "test_template.cpp"

#endif /*__TEMPLATE_HPP__*/
hoge.cpp
#ifndef __TEMPLATE_CPP__
#define __TEMPLATE_CPP__

#include <iostream>
#include "test_template.hpp"

using namespace std;

template<class T>
Hoge<T>::Hoge( T _val ){
  val = _val;
}

template<class T>
void Hoge<T>::show(){
  cout << "val = " << val << endl;
}

#endif /*__TEMPLATE_CPP__*/

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2010年05月10日 21:32
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。