Last active
December 30, 2015 02:59
-
-
Save fand/7766673 to your computer and use it in GitHub Desktop.
include .cpp to .hpp in C++ template class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
template<class T> | |
class TempClass{ | |
public: | |
TempClass(); | |
~TempClass(); | |
void input(T val); | |
T output(); | |
private: | |
T memory; | |
}; | |
#include "tempclass.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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