Solved by added a default constructor to the symbol struct, but also I would like to ask why there is a call to a default constructor if possible. If not, it's fine. thanks.
I'm trying to write a tree, but when I define a node like so:
TreeNode<SymbolPriority>* treeRoot =
new TreeNode<SymbolPriority>(SymbolPriority('a', 1));
I can't compile and it throws an Error c2512 'SymbolPriority': no default appropriate default constructor
; however, in my struct I have the constructor I am trying to use, and I have used it before, so I do not know what is going on.
I have tried this:
SymbolPriority aSymbol( 'a', 1 );
TreeNode<SymbolPriority>* treeRoot = new TreeNode<SymbolPriority> (aSymbol);
but it doesn't work either.
I put down the relevant code below:
template<typename DATA_TYPE> struct TreeNode
{
TreeNode(const DATA_TYPE& value, TreeNode* left = NULL, TreeNode* right = NULL)
{
Value = value;
Left = left;
Right = right;
}
DATA_TYPE Value;
TreeNode* Left;
TreeNode* Right;
bool IsLeaf() const
{
return Left == NULL && Right == NULL;
}
};
and
struct SymbolPriority
{
SymbolPriority(char aSymbol, int priority){
Symbol = aSymbol;
Priority = priority;
};
char Symbol;
int Priority;
bool operator > (const SymbolPriority& compareTo) const{
return (Priority > compareTo.Priority );
};
bool operator < (const SymbolPriority& compareTo) const{
return !( *this > compareTo);
};
bool operator==(const SymbolPriority& compareTo) const{
return (Priority == compareTo.Priority );
};
};