• Register
0 votes
79 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".

7 5 2
3,870 points

Please log in or register to answer this question.

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.

9 7 4
38,600 points

Related questions

0 votes
1 answer 71 views
0 votes
1 answer 32 views
0 votes
1 answer 13 views
13 views
Problem: First off I would like to say I've seen the previous questions on this site, I've tried every solution but none fit my use case or solves my problem. I am having trouble with the g++ complier being recognized, I've included this path: C:\ ... has double quotes around it , so i tried editing the path to contain double quotes around it and the path automaticlly changes back after saving.
asked Apr 25 sumaiya simi 43.9k points
0 votes
1 answer 128 views
128 views
Problem: I am having only fundamental knowledge of g++. Now I am trying to compile my code using g++ and either the with the use of -std=c++11 or c++0x flags. But I am facing below error: cc1plus: error: unrecognized command line option "-std= ... . This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
asked Aug 11, 2020 Raphael Pacheco 4.9k points
1 vote
1 answer 13 views
13 views
Problem : I came across this issue > CreateProcess() failed with error code 2: The system cannot find the file specified.
asked Apr 29 Abik Dey 4k points
0 votes
1 answer 1.3K views
1.3K views
Problem : I am completely new to the Notepad++ and C++ programming language. I am unable to figure out that what has gone wrong in my coding, may be it might look simple to resolved to many. I tried a lot to search for the solution, but without any ... NppExec script taken as below : NPP_SAVE CD $(CURRENT_DIRECTORY) Compiled.exe -c -w "$(FILE_NAME)" Please guide me in resolving this issue.
asked Dec 16, 2019 alecxe 7.5k points
0 votes
1 answer 7 views
7 views
Problem: I have created a C++ project which uses the nullptr and auto keywords. The build gives the following errors:- ../{filename}.cpp:13:13: error: ‘nullptr’ was not declared in this scope
asked Apr 19 ummesalma 29.2k points
0 votes
1 answer 3 views
3 views
Problem: I am trying to execute my first "Hello World!" in C++. I am using Windows XP But I get: 'g++' is not recognized as an internal or external command, operable program or batch file.
asked Apr 18 ummesalma 29.2k points
0 votes
1 answer 4 views
4 views
Question: I'm trying to write a program for a simple game, but I am getting errors, stray &lsquo;\342&rsquo; and &lsquo;\200&rsquo; and &lsquo;\214&rsquo;, using g++ and gedit in Ubuntu 13.10 (Saucy Salamander). The code is: #include <iostream> #include <cctype> using namespace ... ' in program a.cpp:8:2: error: stray \214' in program How can I fix this? Note that I installed Ubuntu last night.
asked Apr 13 Atik03 26.5k points
0 votes
1 answer 10 views
10 views
Problem: My program that gives this error is: #include <string> int main() { std::to_string(0); return 0; }
asked Mar 17 ummesalma 29.2k points