Im implementing BinarySearchNode class which inherits from BinaryNode class.
BinaryNode fields are:
//|-------------------- Protected fields --------------------|
protected:
U value;
T key;
BinaryNode<T,U>* left;
BinaryNode<T,U>* right;
BinaryNode<T,U>* parent;
and BinarySearchNode does not have any additional fields. I'm getting error with the implementation of the method insert
in the BinarySearchNode class:
ifndef BINARYSEARCHNODE_H
#define BINARYSEARCHNODE_H
#include <iostream>
#include "BinaryNode.h"
template <class T,class U>
class BinarySearchNode : public BinaryNode<T,U>
{
public:
//|--------------------- Constructors ----------------------|
BinarySearchNode(const T key, const U& data): BinaryNode<T,U>(key,data) {}
//|------------------------ Methods ------------------------|
virtual void insert(const T key, const U& data){ //throw (char*)
if(key < this->key){
if(!(this->left)){
this->left = new BinarySearchNode(key, data);
this->left->parent = this;
}
else
this->left->insert(key,data);
}
if(this->key < key){
if(!(this->right)){
this->right = new BinarySearchNode(key,data);
this->right->parent = this;
}
else
this->right->insert(key,data);
}
if(this->key == key)
throw "Error: Key already exists in the tree.";
}
The error I get is:
error: 'BinaryNode<int, int>* BinaryNode<int, int>::parent' is protected within this context|
But since BinarySearchNode inherits from BinaryNode I cannot understand why cant I get an access to protected field of the base class.
Any help would be appreciated. Thanks in advance.