-2

This is a homework related question, but the compiler issue isn't the homework, I've already implemented the function I needed to write, just need to figure out this compiler error now.
I've tried searching and so far the results I get which come close to my question don't fit what causes my compiler error.

From binaryTree.h :

#include <iostream>
#include "orderedLinkedList.h"

using namespace std;
// Definition of the Class
template <class elemType>
class binaryTreeType
{

[rest of definition]

public:
[rest of declarations]
    void createList(orderedLinkedList<elemType>& list);
[rest of declarations]
private:
    void inorderToList(nodeType<elemType> *p, orderedLinkedList<elemType>& tList) const; 
[.... then the definitions]
template <class elemType>
void bSearchTreeType<elemType>::createList(orderedLinkedList<elemType>& tList)
{
    inorderToList(this->root, tList);
}

// copies to list
template <class elemType>

void bSearchTreeType<elemType>::inorderToList(nodeType<elemType> *p, 
                                              orderedLinkedList<elemType>& tList) const
{
    if (p != NULL)
    {
        inorder(p->lLink);
        tList.insert(p->info);
        inorder(p->rLink);
    }   
 }

I receive the errors :

binaryTree.h:250: error: expected initializer before ‘<’ token

binaryTree.h:257: error: expected initializer before ‘<’ token

The function definitions for createList() and inorderToList() are the ones are line 250 and 257 respectively. So I'm a little confused as to what I'm doing wrong here, and sure it's something simple.

  • `using namespace std;` you should never put this in a header file, but seeing as you did this can cause problems if you have `std::list` included in from somewhere else. – shuttle87 Dec 01 '14 at 04:27
  • 1
    You've shown a partial declaration of `binaryTreeType` and function definitions for `bSearchTreeType`. Is this intentional? Are the types related? – etheranger Dec 01 '14 at 04:28
  • @etheranger : Not intentional, was just trying to save space and show relevant code, would t be helpful to show the entire thing and/or the orderedLinkedList.h file? – WoodenCode Dec 01 '14 at 04:33
  • @shuttle87: just searched the code, no inclusion of list (we're writing it all from scratch for the class), that gave me an idea that I might have a name conflict though, and changed the parameter name from **list** to **tList**, still receiving the same error. – WoodenCode Dec 01 '14 at 04:36
  • @WoodenCode, just pointing out that this can be a problem and hence why the guideline exists. If you want to cut down on typing just bring in the thing you are using into the namespace by doing something like `using std::cout` as opposed to `using namespace std;` there's more info about this here: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice – shuttle87 Dec 01 '14 at 04:42

1 Answers1

0

Ok, figured out what I was doing wrong.

I originally had the template in a derived class (bSearchTreeType) and forgot to update the method definitions when I moved it into the parent class.

So the new code (line 250 and 257):

template <class elemType>
// below is 250
void binaryTreeType<elemType>::createList(orderedLinkedList<elemType>& tList)
{
[... same as in original post]
}

template <class elemType>
// below is 257
void binaryTreeType<elemType>::inorderToList(nodeType<elemType> *p, 
                orderedLinkedList<elemType>& tList) const
{
[... same as in original post]
}