Dzień dobry!
Moim zadaniem jest stworzyć Drzewo binarne zawierające w sobie liczby urojone. Jedno i drugie musi być strukturą (struct) oraz jedno i drugie musi mieć swój szablon. Mój kod wygląda jak poniżejj, jednak cały czas przy kompilacji występuje błąd i nie potrafię dojść do tego, dlaczego tak się dzieje. Będę wdzięczny za każdą pomoc
#include "pch.h"
#include <iostream>
#include <memory>
#include <fstream>
using namespace std;
// definicja struktury i deklaracje funkcji
template <typename T>
struct Complex
{
T real;
T img;
Complex(T dataR, T dataI)
{
this->real = dataR;
this->img = dataI;
}
Complex(T data)
{
this->real = data;
this->img = data;
}
Complex()
{
this->real = 0;
this->img = 0;
}
};
template <typename T>
struct BstNode
{
std::unique_ptr<BstNode> left;
T value;
std::unique_ptr<BstNode> right;
BstNode(int value) {
this->value = value;
left = nullptr;
right = nullptr;
}
BstNode() {
this->value = 0;
left = nullptr;
right = nullptr;
}
};
template <typename T>
std::fstream& operator << (std::fstream& stream, const Complex<T>& p) {
stream.open("plik.txt");
if (stream)
{if (p.img>=0)
return stream << p.real << "+" << p.img << "i";
else
return stream << p.real << " " << p.img << "i";
}
stream.close();
}
template <typename T>
std::ostream & operator<<(std::ostream& stream, BstNode<T> *bst)
{
if (bst != nullptr)
stream << bst->left.get() << bst->value << endl << bst->right.get();
return stream;
}
template <typename T>
void addToTree(std::unique_ptr<BstNode<T>>& bst, int value)
{
if (bst) {
if (bst->value > value) {
addToTree(bst->left, value);
}
else if (bst->value < value) {
addToTree(bst->right, value);
}
}
else {
bst = std::make_unique<BstNode<T>>(value);
}
}
int main()
{
std::unique_ptr <BstNode<Complex<int>>> bst = nullptr;
Complex<int> z1;
z1.real = 10;
z1.img = 10;
addToTree(bst, z1);
addToTree(bst, z1);
addToTree(bst, z1);
addToTree(bst, 15);
cout << bst;
cout << minimum(bst.get()) << endl;
cout << maximum(bst.get()) << endl;
//cout << bst << endl;
}