Witam! Utworzyłem 3 klasy:
class Node
{
public:
int count;
string word;
Node *left, *right;
//Konstruktory
Node();
Node(string _word);
//Funkcje składowe
void Print();
//Przeciążanie operatorów
friend ostream &operator<<(ostream &, Node *);
};
class Tree
{
Node *root;
public:
//Konstruktor i destruktor
Tree();
~Tree();
//Funkcje składowe
void Print();
void Add(string word);
private:
Node *Add(Node *root, string word);
void Free(Node *root);
void Print(Node *root, int depth);
//Przeciążanie operatorów
friend ostream &operator<<(ostream &, Tree &);
};
class Dictionary
{
Tree T;
public:
//Konstruktory i destruktory
Dictionary() {}
Dictionary(string);
~Dictionary() {};
//Funkcje składowe
void Print();
void Read(istream &);
private:
string getWord(istream &);
string stringToLower(string);
//Przeciążanie operatorów
friend ostream &operator<<(ostream &, Dictionary &);
};
Dla każdej klasy chciałem przeciążyć operator "<<":
ostream &operator<<(ostream &out, Node *root)
{
if (root) out << root->word << ": " << root->count;
return out;
}
ostream &operator<<(ostream &out, Tree &T)
{
if (T.root)
{
out << T.root->left << " " << T.root << " " << T.root->right;
}
return out;
}
ostream &operator<<(ostream &out, Dictionary &D)
{
out << D.T << endl;
return out;
}
Generalnie program działa, ale tylko dla pierwszych dwóch węzłów, co oznacza że gdy chce wypisać słowa "Ala ma kota" to wypisuje tylko Ala ma. Byłbym wdzięczny za podpowiedź co robię źle.
PS Coś źle skopiowało.