MK3GTX
MK3GTX

Reputation: 241

Error: 'template<class T> class Two' used without template parameters

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

Answers (1)

Pete Becker
Pete Becker

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

Related Questions