I'm trying to create two overloaded operators in a template BSTree.h and am encountering errors that really don't tell me what the problem is. Running a search on the error codes seperate or in conjunction hasn't yielded anything for me.
The first overloaded<< for the BSTree doesn't cause any errors on compile, but the 2nd overloaded<< I created for my Node struct keeps returning the following errors:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '*'
#ifndef BSTREE_H
#define BSTREE_H
#include <iostream>
#include <fstream>
template <typename T>
class BSTree{
friend ostream& operator<<(ostream&, const BSTree<T>&);
public:
BSTree();
//BSTree(const BSTree &);
~BSTree();
void buildTree(ifstream&);
void setType(char);
bool getType(char);
bool insert(T*);
bool isEmpty();
private:
char type;
struct Node{
T* data;
//subnode[0] == left subtree
//subnode[1] == right subtree
Node* subnode[2];
};
Node* head;
void destructorHelper(Node* &);
bool insertHelper(T*, Node* &);
friend ostream& operator<<(ostream&, const Node*&);
};
The compiler says the errors occur at the line where the Node overloaded<< code is.
template <typename T>
ostream& operator<<(ostream &output, const BSTree<T> &out) {
if(head != NULL)
output << head;
return output;
}
template <typename T>
ostream& operator<<(ostream &output, const Node* &out) {
if(out != NULL){
output << out->subnode[0];
output << *out->data;
output << out->subnode[1];
}
return output;
}
Am I not allowed to declare 2 overloaded<< in the same .h even if they are for different objects? Or am I messing something up in my code?