Daniel
Daniel

Reputation: 6755

Error: expected a declaration

So far all I have in my DecisionTree.h file is

namespace DecisionTree
{
     public static double Entropy(int pos, int neg);
}

and Visual Studio is already highlighting the public and saying

Error: expected a declaration.

What am I missing?

Upvotes: 6

Views: 34320

Answers (2)

It will definitely give an error, for you dint declared any class,struct, or enum and directly you have written a static function inside a namespace. So, first write a class definition inside a namespace and then a function.

Upvotes: 0

iammilind
iammilind

Reputation: 69988

public is an access specifier. Access specifiers are applicable only within class/struct body and not inside namespace. In C++ (unlike Java) it must be followed by a colon : inside the class body.

For example,

class DecisionTree {  // <----- 'class' (not 'namespace')
public:  // <------ access specifier
  static double Entropy (int pos, int neg);
private:
  int i;
};

Upvotes: 9

Related Questions