What i'm whilling to do is to create a basic Tree that accepts all kind of data.
But i get an error when trying to dynamically initializate an arm.
The Tree should work like this:
Father->Son(Where son is a list of Sons)
And when i do Son->Add(new ArmS<T>) it requires me to put an int insthead of *int
\Projects\Tree\tree.h||In instantiation of 'void Tree<T>::NewArm(T) [with T = int]':|
\Tree\main.cpp|14|required from here|
\tree.h|36|warning: suggest parentheses around assignment used as truth value [-Wparentheses]|
\Tree\tree.h|42|error: no matching function for call to 'List<ArmS<int> >::Add(ArmS<int>*)'|
\Tree\tree.h|42|note: candidate is:|
\Tree\list.h|52|note: T List<T>::Add(T) [with T = ArmS<int>]|
\Tree\list.h|52|note: no known conversion for argument 1 from 'ArmS<int>*' to 'ArmS<int>'|
\Tree\tree.h|44|error: base operand of '->' has non-pointer type 'ArmS<int>'|
\Tree\tree.h|45|error: base operand of '->' has non-pointer type 'ArmS<int>'|
\Tree\tree.h||In instantiation of 'ArmS<T>* Tree<T>::Down() [with T = int]':|
\main.cpp|15|required from here|
\Tree\tree.h|84|error: cannot convert 'ArmS<int>' to 'ArmS<int>*' in assignment|
||=== Build finished: 4 errors, 5 warnings (0 minutes, 0 seconds) ===|
OK, i got another problem, here is the changed tree.h
What i'm willing to do is this:
First i add something, then i add 2 sons,
then i go down to the first son and try to add a son.
But my program crashes..
template <class T>
T List<T>::Return(int Selection)
{
if(Selection > this->End->N) // what happens when this->End is null?
{
returnthis->End->Item;
}
else
{
bool found = true;
Object<T> *ToFound;
ToFound = this->Start; // what happen when this->Start is null?
do
{
if(Selection == ToFound->N)
{
found = true;
}
else
{
ToFound = ToFound->Next;
found = false;
}
}
while(found != true);
return ToFound->Item; // what will happen if ToFound is null?
}
}
Your're trying to find the object (usually named as node) by the index, but the way you use the index in the tree does not correlate with the index in the list. For instance
this->CurrentArm->NumberOfSons in a subtree might be 1, but there might be a lot of others in other branches/'arm's. The indexes in the list are continuous hence 1 is a complete different 'arm'