Skip to content

Instantly share code, notes, and snippets.

@fand
Last active December 30, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fand/7766673 to your computer and use it in GitHub Desktop.
Save fand/7766673 to your computer and use it in GitHub Desktop.
include .cpp to .hpp in C++ template class
#include <iostream>
template<class T>
TempClass<T>::TempClass(){
std::cout << "new" << std::endl;
}
template<class T>
TempClass<T>::~TempClass(){
std::cout << "delete" << std::endl;
}
template<class T>
void
TempClass<T>::input(T val){
this->memory = val;
}
template<class T>
T
TempClass<T>::output(){
return this->memory;
}
#pragma once
template<class T>
class TempClass{
public:
TempClass();
~TempClass();
void input(T val);
T output();
private:
T memory;
};
#include "tempclass.cpp"
#include <iostream>
#include <string>
#include "tempclass.hpp"
int main(){
TempClass<int> t_int;
TempClass<std::string> t_string;
t_int.input(12345);
t_string.input("皆と同じようにiPodの手術を受けたい");
std::cout << "int: " << t_int.output() << std::endl;
std::cout << "string: " << t_string.output() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment