c++ template 的包含模型

定义:.h(声明)文件 和.cpp( 定义)文件分别在不同的文件中,  在main.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----- 在main.cpp文件中包含.cpp(定义文件)

#include "firstdef.cpp"
      2 int main()
      3 {
      4     int i = 2;
      5     print_typeof(2);
      6 }



你可能感兴趣的:(C++,iostream)