Overloading [] and Ternary trees

I am trying to build a ternary tree. How do I overload the [] operator so that when the main executes a[key1] = key2;, key1 and key2 will be added to the tree in the same node?



#include <iostream>
using namespace std;

class Tree;

class Node{
Node() : root(NULL);
friend class Tree;
private:
int keyInt;
double keyDouble;
Node *leftTree;
Node *centerTree;
Node *rightTree;
};

class Tree{
public:
Tree();
~Tree();
private:
void deleteSubtree(Node*& subTreeRoot);
Node *root;
};

int main(){

Tree a;
a[5] = 42.2;
a[-2] = 67.2;
a[1] = 89.7;
}

Tree::Tree() : root(NULL){}

void Tree::deleteSubTree(Node*& subTreeRoot){
if (subTreeRoot != NULL){
deleteSubTree(subTreeRoot->leftTree);
deleteSubTree(subTreeRoot->rightTree);

delete subTreeRoot;
subTreeRoot = NULL;
}
}

Tree::~Tree(){
deleteSubtree(root);
}
Thank you for giving my the chance to provide this response.

http://lmgtfy.com/?q=c%2B%2B+overload+subscript+operator
Topic archived. No new replies allowed.