Home » Community » Coffee corner » important note when a strange compilation error occurs
important note when a strange compilation error occurs [message #57296] |
Sat, 26 June 2021 21:42  |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
Hi,
Suddenly, through an unnoticed distraction, a strange compilation error occurs.
It happened to me, although it solved with some slowness, because I was evaluating the reason, as that something difficult to visualize in the code suddenly happened (in this case, it involved many lines of code).
the ide show errors like
...'using namespace' is not allowed in classes
...non-friend class member 'Get' cannot have a qualified name
class....{}
public:
....
....
....
void getTiposCartao(){; // <----- I accidentally pasted a bracket and didn't notice.
....
....
};
that's why I think good practices such as writing function and as soon as it ends compiling before writing others function or the next code.
Thanks
|
|
|
|
Re: important note when a strange compilation error occurs [message #57298 is a reply to message #57297] |
Sun, 27 June 2021 17:49   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
According to the standard following line is valid code:
You are opening function scope and add empty instruction. Please noticed that you can place whatever number of semicolons as you want:
void getTiposCartao(){;;;;;;; // <- valid
Why it is so? In C/C++ you are not force to write instruction per line - it is good habbit, but you have flexibility:
void getTiposCartao(){int a = 4;++a;int b = a + 10;for(int i = 0; i < 10; ++i){};;;} // <- You could process universe in the single function ;)
For the readability reason nobody should write code like this... This is not something we could fix within TheIDE. It is how the language is defined.
On the other hand following code:
is invalid due to parenthesis mismatch.
Klugier
U++ - one framework to rule them all.
[Updated on: Sun, 27 June 2021 17:52] Report message to a moderator
|
|
|
Re: important note when a strange compilation error occurs [message #57299 is a reply to message #57298] |
Sun, 27 June 2021 20:05  |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
Hi Klugier,
I understand your placement.
I don't have experience with c/c++, but considering from beginning to end of the code (total), if not close the bracket and semicolon "};" understand that the compiler will return to the first line of a new function, for example, and will display an error message in the format
(file name);( line); error function definition is not allowed here (this error for my case).
In my case, the error was in the header file "file.h" and the compiler showed the 1st line of another function that was in the file "file.cpp", ie considering large files, the situation was visually difficult to be solved.
Thanks!
|
|
|
Goto Forum:
Current Time: Sat May 10 23:22:09 CEST 2025
Total time taken to generate the page: 0.01096 seconds
|