• 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

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


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 19 views
0 votes
1 answer 17 views
0 votes
1 answer 68 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
0 votes
1 answer 984 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 40 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, 2020 Gavin 15.3k points
0 votes
1 answer 2 views
Problem: suggest parentheses around assignment used as truth value
asked 1 day ago Ethan ross 1.8k points
0 votes
1 answer 3.6K views
Problem: I am currently wondering why I am getting below compile error if I just declare variable with var or let keywords? I want to say, below code goes well: export class MyAppComponent { myRefreshClickStream$: any; constructor(){ } } While this brings the error: export class MyAppComponent { var myRefreshClickStream$: any; constructor(){ } }
asked Jan 27, 2020 jwilliam 3.9k points
0 votes
1 answer 20 views
Problem Hey, I was writing a class for finding the average of grades outside the class but I Am facing an error named expected initializer before token. Can someone help me to resolve this error Here is my code Program:  #include <iostream> using std::cout; using std::cin; ...   computeAverage = computeAverage + gradeAverage.getGrade();     }     cout << computeAverage/5 << endl;     return 0; }
asked Dec 22, 2020 chris jordan 2.4k points
1 vote
1 answer 52 views
Problem: I am in the process of understanding C++ Programming. Currently I am in trouble because of my below C++ program. I have tried to fix it by my own efforts but I am unable to fix the below error. [Error] a function-definition is not allowed here before '{' token ...     mydisplaymenu();     system("pause");     return 0; } I am looking for C++ expert who can help me in fixing above program.
asked May 26, 2020 Martin K 6.6k points
1 vote
2 answers 203 views
Problem : I am trying to learn the GCC. If I execute the below command then I always face the following error. make -j4 Error received: checking for suffix of object files... configure: error: in `/mnt/LFS/source/gcc-4.6.2/x86_64-lfs-linux-gnu/libgcc': configure: ... See `config.log' for more details. make[1]: *** [configure-target-libgcc] Error 1 Can somebody guide me in fixing above error?
asked Mar 27, 2020 morrisBson 3.2k points