开发者

Error: expected a declaration

开发者 https://www.devze.com 2023-04-09 02:45 出处:网络
So far all 开发者_开发知识库I have in my DecisionTree.h file is namespace DecisionTree { public static double Entropy(int pos, int neg);

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?


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;
};


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号