• Register
0 votes
25 views

Problem :

I want to compile my code to test my function to read and print the data file, but I get the compiling error that I don't understand as follows

"Error: expected constructor, destructor, or type conversion before ';' token".

by (3.9k points)  

1 Answer

0 votes

Solution :

The line with a error looks like you want to call GetMonth -- but at your global level, a C++ program consists of the series of declarations. Since the function call isn't the declaration, it can't exist in a isolation at a global level. You can have the declaration that's also the definition, in which case it can invoke your function as part of initialization.

The function call by itself, but has to be contained within some or the other function:

#ifdef MYTEST
int main() { 
    GetMonth();
}
#endif

OR

In order to execute the 'GetMonth()' function you need to either call it from the another function ('main' or whatever is called from the 'main') or use it in the initializer expression of the object declared at your namespace scope, as in

double global_dummy = GetMonth();

But the latter method might suffer from the initialization order problems, which is why it is recommended to use a former method whenever it is possible.

by (36.1k points)  
...