-1

I would like to convert my Binary search tree class but ran into some problems. Below is a snippet of the code which triggers an error when i compile the class.

template <class Type>
BST*BST <Type>:: Insert(BST *root, Type value)
{
    if(!root)
    {
        return new BST(value);
    }
    if(value > root->data)
    {
        root->right = Insert(root->right, value);
    }
    else
    {
        root->left = Insert(root->left, value);
    }
    return root;
}

The error message i got is, error: invalid use of template-name 'BST' without an argument list. BST is short for binary search tree. I name my Binary search tree class BST.

Md Fairus
  • 19
  • 6
  • 1
    Does this answer your question? [invalid use of template-name Queue without an argument list](https://stackoverflow.com/questions/16683838/invalid-use-of-template-name-queue-without-an-argument-list) – Botje Mar 09 '20 at 14:27
  • The shown code in this question fails to meet stackoverflow.com's requirements for a [mre], and because of that it is unlikely that anyone on stackoverflow.com can determine the problem. This question must be [edit]ed to show a minimal example, no more than one or two pages of code (the "minimal" part), that anyone can cut/paste, compile, run, and reproduce the described problem (the "reproducible" part) ***exactly as shown*** (this includes any ancillary information, like the input to the program). See [ask] for more information. – Sam Varshavchik Mar 09 '20 at 14:34
  • `BST` is not a class, it's a class template. There are very few situations where you can use the name of a template on its own without parameters, and the return type of a function is not one of them. – molbdnilo Mar 09 '20 at 15:47

1 Answers1

0

You're missing the template argument list in your parameter BST* root. It should be BST<Type>* root instead.

user3520616
  • 60
  • 3
  • 17
  • 2
    Probably best to spell it out verbatim with a code-formatted example of the corrected code. – Wyck Mar 09 '20 at 14:30
  • 1
    This does not seem to be correct, due to template name being injected into the template declaration. You should always try to verify that your answer is correct by compiling it and seeing if your proposed answer fixes the compilation error. In this case it is not possible to do so since the question fails to meet all requirements for a [mre], as explained in the [help]. – Sam Varshavchik Mar 09 '20 at 14:33
  • Not the argument `root` is the problem but have a look at the return type (where template name injection doesn't work). ;-) [**Live Demo on coliru**](http://coliru.stacked-crooked.com/a/028f93852c66a3da) – Scheff's Cat Mar 09 '20 at 15:17