Created
October 17, 2014 09:17
-
-
Save mrexodia/a45da71e3b0dc11db9bf to your computer and use it in GitHub Desktop.
Template Header/Source
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
//http://www.codeproject.com/Articles/48575/How-to-define-a-template-class-in-a-h-file-and-imp | |
#include <iostream> | |
#include <vector> | |
#include "Test.h" | |
#include "Test.cpp" | |
int main() | |
{ | |
int n; | |
std::cout << "Input Number: "; | |
std::cin >> n; | |
Test<int> test(n); | |
std::cout << "Value: " << test << std::endl; | |
return 0; | |
} |
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 "Test.h" | |
template<class T> | |
Test<T>::Test(T val) | |
{ | |
this->val = val; | |
} | |
template<class T> | |
const T & Test<T>::operator=(T val) | |
{ | |
return this->val = val; | |
} | |
template<class T> | |
Test<T>::operator const T & () | |
{ | |
return this->val; | |
} |
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
#ifndef TEST_H | |
#define TEST_H | |
template<class T> | |
class Test | |
{ | |
private: | |
T val; | |
public: | |
Test(T val); | |
const T & operator=(const T val); | |
operator const T & (); | |
}; | |
#endif //TEST_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment