Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 661
Daniel Avatar asked Sep 28 '11 04:09

Daniel


People also ask

What is expected declaration error?

'Expected declaration` basically means that you should have defined something before using it. There are multiple fixes to this error: If you are trying to declare a variable or constant, be sure that you have a let or var at the beginning.

What does error expected declaration or statement at end of input mean?

Normally that error occurs when a } was missed somewhere in the code, for example: void mi_start_curr_serv(void){ #if 0 //stmt #endif. would fail with this error due to the missing } at the end of the function. The code you posted doesn't have this error, so it is likely coming from some other part of your source.

What does error Expected mean in C?

It means the syntax is invalid.

What does expected unqualified ID mean?

The expected unqualified id error shows up due to mistakes in the syntax. As there can be various situations for syntax errors, you'll need to carefully check your code to correct them. Also, this post points toward some common mistakes that lead to the same error.


1 Answers

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;
};
like image 175
iammilind Avatar answered Sep 20 '22 18:09

iammilind