All pastes #162021 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-09-06 01:22 UTC
rendered paste body
BNode.h

#include <iostream>

class BNode {
   private:
      int data;
      BNode *left, *right;

   public:
      BNode (int d=0, BNode *l=NULL, BNode *r=NULL);
      BNode (const BNode &node); // Not necessary. For example purposes.
      
      bool operator==(int value) const;
      bool operator> (int value) const;
      bool operator< (int value) const;

   friend bool operator==(int value, const BNode &node);
   friend bool operator> (int value, const BNode &node);
   friend bool operator< (int value, const BNode &node);

   // output this node's entire subtree (left, data, and right).
   friend std::ostream &operator<< (std::ostream &out, const BNode &node);
   
   friend class BST;
};

   

BNode.cpp
#include "BNode.h"


BNode::BNode (int d, BNode *l, BNode *r) : 
data (d), left (l), right (r) {
}

BNode::BNode (const BNode &node) : data (node.data), left (node.left), 
                                   right (node.right) {
}

bool BNode::operator==(int value) const{
   return (this->data==value);
}

bool BNode::operator> (int value) const{
   return (this->data>value);
}

bool BNode::operator< (int value) const{
   return (this->data<value);
}      


bool operator==(int value, const BNode &node) {
   return (node.data==value);
}

bool operator> (int value, const BNode &node) {
   return (node.data>value);
}

bool operator< (int value, const BNode &node) {
   return (node.data<value);
} 


friend std::ostream &operator << (std::ostream &out, const BNode &node){   //line 38
   if(node.left != NULL){
      out << node.left;
   }
   
   out << node.data << " ";

   if(node.right != NULL){
      out << node.right;
   }
} 

Errors: 
BNode.cpp:38: error: can't initialize friend function `operator<<'
BNode.cpp:38: error: friend declaration not in class definition