jordpw
jordpw

Reputation: 181

Template Error -- C++

I am getting an error ("default template arguments are only allowed on a class template") when I use my template in the following way. I have included the template declaration for the class, as well as one of the functions.

template<typename K, typename T, bool RINSERT = true>
class BST
{
public:
BST();
.
.
.

... and so on. Heres a function that uses these paramters:

template<typename K, typename T, bool RINSERT = true>
int BST<K,T,RINSERT>::size() const {
return nodes;
}

Am i declaring the function incorrectly?

Upvotes: 0

Views: 82

Answers (1)

Mike Seymour
Mike Seymour

Reputation: 254431

You've already declared the default argument on the class template; don't redeclare it on the member definition:

template<typename K, typename T, bool RINSERT>
int BST<K,T,RINSERT>::size() const {
    return nodes;
}

Upvotes: 5

Related Questions