c++templateの含むモデル
定義:h(宣言)ファイルと.cpp(定義)ファイルはそれぞれ異なるファイルの中でmain.cppファイルに含む.cpp(定義ファイル)
first.h
firstdef.cpp
main.cpp-----
メールでcppファイルに含む.cpp(定義ファイル)
first.h
#include <iostream>
#include <typeinfo>
using namespace std;
template<typename T>
void print_typeof(T const&);
firstdef.cpp
#include "first.h"
2
3 template<typename T>
4 void print_typeof(T const &x)
5 {
6 cout<<typeid(x).name()<<endl;
7 }
main.cpp-----
メールでcppファイルに含む.cpp(定義ファイル)
#include "firstdef.cpp"
2 int main()
3 {
4 int i = 2;
5 print_typeof(2);
6 }