A C++ class definition is like a blueprint for something that doesn't exist yet, as such until you actually create an instance of the class, there is no variable to set to zero at initialisation. This is what the compiler is complaining about.
The only time that this would be valid is if the variable was declared static
, but this would mean that every single instance of the class would effect the single static
variable.
There are two solutions to this, as stated in the comments you could simply tell the compiler to use the C++11 standards which allow this method of initialisation, or you can use the more common and compatible method with older compilers which is to initialise it in the constructor (as you are already doing for root
), like so:
class BinarySearchTree
{
public:
Node* root;
int countHight;
BinarySearchTree()
{
root = NULL;
countHight = 0;
}
~BinarySearchTree()
{
return;
}
void insert(int value);
void display(Node* temp);
void DisplayByLevel(Node* temp,int level);
};