I'm trying to mix it up with operator overloading and I can figure out what I'm doing wrong. Here's the code:
#ifndef TEST_H
#define TEST_H
using namespace std;
template <typename T>
class Test
{
private:
T number;
public:
Test(T);
friend Test operator+(Test<T> &a, Test<T> &b);
friend ostream& operator<<(ostream& out, const Test<T> &obj);
};
template <typename T>
Test<int>::Test(T num1)
{
number = num;
}
template <typename T>
Test<int> operator+(Test<T> &a, Test<T> &b)
{
return Test(a.number + b.number);
}
template <typename T>
ostream& operator<<(ostream& out, Test<T> &obj)
{
out<< obj.number;
return out;
}
#endif
#include <iostream>
#include "Test.h"
using namespace std;
int main()
{
Test<int> obj1(5);
Test<int> obj2(2);
Test<int> obj3(0);
obj3 = obj1 + obj2;
cout << obj3;
return 0;
}
I'm getting an error that says "test.h(21): error C2244: 'Test<T>::{ctor}' : unable to match function definition to an existing declaration"