• Register
0 votes

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

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() { 


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 9 views
0 votes
1 answer 9 views
0 votes
1 answer 21 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 Raphael Pacheco 4.9k points
0 votes
1 answer 634 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
2 votes
1 answer 26 views
Problem: Please find out the problem in my code and let me know where I am wrong. #include <iostream> #include <string> using namespace std; string userInput(); int wordLengthFunction(string word); int permutation(int wordLength); int main() { string word = userInput(); ... (int wordLength) { if (wordLength == 1) { return wordLength; } else { return wordLength * permutation(wordLength - 1); } }
asked Mar 7 Gavin 15.3k points