Reputation: 241
Hey so I'm trying to compile:
//ASSIGNMENT
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Two {
private: T x,y;
public:
Two (T a, T b);
friend void Show (Two p);
~Two();
};
//ASSIGNMENT
template <class T>
Two::Two (T a, T b){
x = a;
y = b;
}
friend void Two::Show(Two p){
cout << p.x << " and " << p.y << endl;
}
int main () {
Two<int> class2(2,3);
Show(class2);
}
The assignment was to define the members of the class (in the //ASSIGNMENT tags). I don't know why it won't compile... Thanks!
Upvotes: 1
Views: 7603
Reputation: 76305
Change
template <class T>
Two::Two (T a, T b)
to
template <class T>
Two<T>::Two (T a, T b)
and make the analogous change wherever it's needed.
Upvotes: 3