0

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?

3
  • Why don't you declare it inline? A lot less to write.
    – nvoigt
    Commented May 6, 2014 at 16:46
  • could you further explain that? ive never actually used inline
    – jordpw
    Commented May 6, 2014 at 16:48
  • @jordpw - he's suggesting to write the method within your class declaration: ...BST(); int size() const { .... } - however, this can get messy and doesn't really answer your question - @Mike Seymour already pointed out your error. Commented May 6, 2014 at 16:49

1 Answer 1

5

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.