Skip to content

Instantly share code, notes, and snippets.

@mrexodia
Created October 17, 2014 09:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrexodia/a45da71e3b0dc11db9bf to your computer and use it in GitHub Desktop.
Save mrexodia/a45da71e3b0dc11db9bf to your computer and use it in GitHub Desktop.
Template Header/Source
//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;
}
#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;
}
#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