Skip to content

Instantly share code, notes, and snippets.

@katsuobushiFPGA
Created September 30, 2014 16:25
Show Gist options
  • Save katsuobushiFPGA/4a83d89c5482b9d45bb2 to your computer and use it in GitHub Desktop.
Save katsuobushiFPGA/4a83d89c5482b9d45bb2 to your computer and use it in GitHub Desktop.
//Source.cpp
#include "Header.h"
#include <stdio.h>
int main(){
Test<int> *t = new Test<int>();
t->hello();
t->setValue(2);
printf("getValue:%d", t->getValue());
getchar();
return 0;
}
//Header.h
//インターフェース
template <class T> class Test{
public:
Test();
~Test();
void hello();
void setValue(T v);
T getValue();
private:
T value;
};
//実装
template <class T>
Test<T>::Test(){
};
template <class T>
Test<T>::~Test(){
};
template <class T>
void Test<T>::hello(){
printf("hello\n");
}
template <class T>
void Test<T>::setValue(T v){
value = v;
};
template <class T>
T Test<T>::getValue(){
return value;
};
@katsuobushiFPGA
Copy link
Author

テンプレートの実装はヘッダに書かなければいけないらしい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment