VC6.0 common compilation errors with a solution

  • 2020-04-02 01:13:38
  • OfStack

(1)error C2001: newline in constant

Number: C2001
A new line appears in a constant.
Error analysis:
1. String constant, character constant whether there is a new line.
2. In this statement, whether the end of a string constant is missing double quotes.
3. In this statement, whether the double quotation mark character "" appears in a character creation constant, but does not use the escape character" \" ".
4. In this statement, whether the end of a character constant is missing single quotes.
5. Whether a single or double quote was mistakenly entered at the end of a statement or in the middle of a statement.

(2)error C2015: too many characters in constant

Number: C2015
There are too many characters in the character constant.
Error analysis:
Single quotes indicate character type constants. In general, there must be one and only one character in a single quote (when using an escape, the character represented by the escape is treated as a single character), and this error is thrown if there are more than four characters in a single quote.
This error is also thrown if a character constant in a statement is missing the single quote on the right, such as:
If (x == 'x || x == 'y') {... }
Note that if the number of characters in a single quote is 2-4, the compilation does not report an error, and the output is the ASC code of these letters as an integer (int, 4B) as a whole.

(3)error C2137: empty character constant

Number: C2137
Empty character definition.
Error analysis:
The reason is that two single quotes are used without any characters in between, which is not allowed.

(4)error C2018: unknown character '0x##'

Number: C2018
Unknown character '0x##'.
Error analysis:
0x## is a hexadecimal representation of the character ASC code. Unknown characters here usually refer to full-angle symbols, letters, Numbers, or direct input of Chinese characters. This error will not be raised if full-angle characters and Chinese characters are enclosed in double quotes as part of a string constant.

(5)error C2041: illegal digit '#' for base '8'

Number: C2141
The illegal number '#'(which is usually 8 or 9) appears in the octal system.
Error analysis:
If a numeric constant starts with "0" (with the exception of a simple zero), the compiler considers it to be a base 8 number. For example, "089", "078" and "093" are all illegal, while "071" is legal and equivalent to "57" in the base system.

(6)error C2065: 'XXXX' : undeclared identifier

Number: C2065
The identifier "XXXX" is not defined.
Error analysis:
First, explain what an identifier is. A token is a word that appears in a program in addition to a keyword. It usually consists of letters, Numbers, and underscores. It cannot begin with a number, cannot be repeated with a keyword, and is case-sensitive. Variable names, function names, class names, constant names, and so on are flags. All identifiers must be defined before they are used. There are many USES for flags, so there are many reasons for errors.

1. If "XXXX" is a variable name, it is usually caused by programmers forgetting to define the variable, or by spelling or capitalization errors, so first check that the variable name is correct. (correlation: variable, variable definition)
2. If "XXXX" is a function name, doubt if the function name is undefined. It could be a spelling or capitalization error, or, of course, it could be that the function you're calling doesn't even exist. Another possibility is that you write a function after you call the function, and you don't declare the function before you call it. (relation: function declaration and definition, function prototype)
3. If "XXXX" is the function name of a library function, such as "SQRT" or "fabs", then see if you have included the header file (.h file) where these library functions are located at the beginning of the CPP file. For example, using the "SQRT" function requires the header file math.h. If "XXXX" is "cin" or "cout", then "iostream.h" is generally not included. (correlation: #include, cin, cout)
4. If "XXXX" is a class name, it means that the class is not defined, and the possibility remains that the class was not defined at all, or that spelling or capitalization errors were made, or that the header file was missing, or that the class was used before the declaration. (association: class, class definition)
5. Flags follow the principle of declaration before use. Therefore, whether the variable, function name, class name, must be defined first, then used. If used before and after the declaration, this error will be caused.
6. The C++ scope can also be a trap that causes this error. Variables inside curly braces cannot be used outside of curly braces. Curly braces caused by classes, functions, if, do(while), and for all follow this rule. (association: scope)
An error in one of the previous statements may also cause the compiler to mistake this sentence for an error. If you have an error in the previous variable definition statement, the compiler will assume that the variable was never defined in the subsequent compilation, and all subsequent statements that use the variable will report the error. If there is an error in the function declaration statement, this will cause the same problem.

(7)error C2086: 'XXXX' : redefinition

Number: C2374
Repeat the statement.
Error analysis:
The variable "XXXX" is defined multiple times in the same scope. Check each definition of "XXXX", leaving only one, or change the variable name.

(8)error C2374: 'XXXX' : redefinition; Multiple initialization

Number: C2374
"XXXX" is repeated and initialized many times.
Error analysis:
The variable "XXXX" is defined multiple times in the same scope and initialized multiple times. Check each definition of "XXXX", leaving only one, or change the variable name.

(9)C2143: syntax error: missing '; 'before (identifier)' XXXX '

Number: C2143
A semicolon is missing before the (identifier) XXXX.
Error analysis:
This is the most common compile-time misstatement in VC6. When this error occurs, it is usually not the statement in question that has an error, but the previous statement. Instead, it is more appropriate for the compiler to report a semicolon missing from the end of the previous statement. Any number of errors in the previous statement will cause the compiler to report this error:

There really is a semicolon at the end of the last sentence. Then make up for it.
2. The previous statement was incomplete, or had an obvious syntax error, or didn't count as a statement at all (sometimes accidentally hitting the keyboard).
3. If you find that the error statement is the first line of the CPP file, check that there is no error in this file, but that it contains a header file in double quotes, then check the header file. There may be an error at the end of the header file.

(10)error C4716: 'XXX' : must return a value

Number: C4716
"XXX" must return a value.
Error analysis:
The function declares that it has a return value (not void), but the implementation forgets the return value. Either the function does not return a value, the return value type is void, or the appropriate value is returned before the function ends.

(11) warning C4508: 'main' : function should return a value; 'void' return type assumed

Number: C4508
The main function should return a value. The void return value type is assumed.
Error analysis:

1. The function should have a return value, and the type of return value should be specified when declaring the function. If there is no return value, the return value of the function should be declared as void. If the return value of a function is not declared, the system defaults to int. The error estimate here is that there is no return return value statement in the main function, and the main function either does not declare the type of its return value or does declare it.
2. Warning type error is a warning error, which means that there is not necessarily a fault, the program can still be successfully compiled and linked, but there may be problems and risks.

(12)warning C4700: local variable 'XXX' used without having been initialized

Number: C4700
Warning that the local variable "XXX" is not initialized before use.
Error analysis:
This is a common mistake for beginners, such as the following procedures section will cause such a warning, and the program does have a problem, should be modified, although can compile, link, success - if not modified, the value of x can't be sure how much is random, whether it is the same as the 3 no sense, in the case of bad luck, may in the debug program will then run on the machine, the result seems to be right, but after replace the computer to run again, the result is wrong, beginners are often confused.
Int x;
If (x = = 3) printf (" hello ");


Related articles: