I've a header file which looks like the following
#ifndef BINARY_SEARCH_TREE_H
#define BINARY_SEARCH_TREE_H
struct Node
{
  int data;
  Node *left, *right;
  Node(int data);
};
class BinarySearchTree
{
  Node *head;
 public:
  BinarySearchTree();
  void insert(int data);
  void inorder(Node *cur = head);
};
#endif
and It says
In file included from Binary_Search_Tree.cpp:2:0:
Binary_Search_Tree.h:17:28: error: invalid use of non-static data member ‘BinarySearchTree::head’
   void inorder(Node *cur = head);
                            ^
Binary_Search_Tree.h:13:9: note: declared here
   Node *head;
Note: I've not provided the default value while defining the method. I guess that isn't necessary.
Only static or constant values are allowed for default values ? if yes then why ? Or something else is wrong ?
Aucun commentaire:
Enregistrer un commentaire