Skip to content

Instantly share code, notes, and snippets.

@fand
Last active Dec 30, 2015
Embed
What would you like to do?
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