注意 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__*/
最終更新:2010年05月10日 21:32