VC6.0 Common compilation error hints with solutions

Source: Internet
Author: User
Tags class definition constant function prototype
This article mainly introduces some error prompts that are often encountered in the process of compiling vc++6.0, and gives the error reason and analysis, need friend Karki reference under

(1) Error c2001:newline in constant

Item No: C2001
A newline occurs in a constant.
Error Analysis:
1.① string constants, Word constants quantity, whether there is a newline.
2.② in this statement, whether the tail of a string constant misses double quotes.
3.③ in this statement, there is a double quote character "" In a word Fu Yi constant, but the escape character "" is not used.
4.④ in this sentence, the end of a word constants quantity is missing the single quotation mark.
5.⑤ whether a single or double quotation mark is entered incorrectly in the end of a statement or in the middle of a statement.

(2) Error C2015:too many characters in constant

Item No: C2015
Literal translation: There are too many characters in the constants quantity.
Error Analysis:
Single quotes represent character-type constants. In general, single quotes must have and only one character (the character represented by the escape symbol treats as a character when using an escape character), and this error is raised if the number of characters in the single quotation mark is more than 4.
Also, this error can be raised if a word constants in a statement lacks a single quotation mark to the right, for example:
if (x = = ' x | | | x = = ' Y ') {...}
It is noteworthy that if the number of characters in single quotes is 2-4, the compiler does not complain, and the output is the number of the ASC code of these letters as an integer (int,4b) as a whole.

(3) Error C2137:empty character constant

Item No: C2137
Literal translation: An empty character definition.
Error Analysis:
The reason is that two single quotes are used without any characters in the middle, which is not allowed.

(4) Error c2018:unknown character ' 0x## '

Item No: C2018
The unknown character, ' 0x## '.
Error Analysis:
0x# #是字符ASC码的16进制表示法. The unknown characters, usually refers to full-width symbols, letters, numbers, or directly entered the Chinese characters. If full-width characters and Chinese characters are included in double quotes, they are part of a string constant that does not cause this error.

(5) Error c2041:illegal digit ' # ' for base ' 8 '

Item No: C2141
There is an illegal number ' # ' in the octal system (this number is usually 8 or 9).
Error Analysis:
If a numeric constant starts with "0" (except for the simple number 0), then the compiler considers this to be a 8-digit number. For example: "089", "078", "093" are illegal, and "071" is legal, equivalent to the "57" in the system.

(6) Error C2065: ' xxxx ': undeclared identifier

Item No: C2065
The identifier, "XXXX", is undefined.
Error Analysis:
First, explain what identifiers are. A marker is a word that appears in a program other than a keyword, usually composed of letters, numbers, and underscores, cannot begin with a number, cannot be duplicated with a keyword, and is case-sensitive. Variable names, function names, class names, constant names, and so on, are all markers. All of the markers must be defined before they are used. There are many different uses for markers, so there are many reasons for errors.

1. If "xxxx" is a variable name, it is usually the programmer forgets to define this variable, or the spelling error, case error caused, so, first check the variable name is correct. (Association: variable, variable definition)
2. If "xxxx" is a function name, it is doubtful whether the function name is undefined. It may be a misspelling or a capitalization error, and of course it may be that the function you are calling does not exist at all. There is also the possibility that you write a function after you call the function, and you have not before the call to the function prototype declaration. (Association: function Declaration and definition, function prototype)
3. If "xxxx" is a function name for a library function, such as "sqrt", "fabs", then look at whether you have started to include the header file (. h file) of these library functions in the CPP file. For example, using the "sqrt" function requires a header file MATH.H. If "xxxx" is "cin" or "cout", then generally does not include "iostream.h". (Association: #include, Cin,cout)
4. If "XXXX" is a class name, it means that the class is not defined, and the possibility remains that it is not defined at all, or that the spelling error, or capitalization error, or lack of a header file, or the use of the class before the declaration. (Association: class, class definition)
5. The sign follows the principle of first declaration and use. Therefore, whether the variable, function name, class name, must be defined before use. If used before, the declaration will cause this error.
The scope of the 6.c++ can also be a trap for causing this error. Variables within curly braces cannot be used outside of this curly brace. This rule is followed by curly braces that are caused by classes, functions, if, do, and for. (Association: SCOPE)
7. Errors in one of the preceding statements may also cause the compiler to mistake this sentence. If you have an error in the previous variable definition statement, the compiler will later compile that the variable has never been defined, so that all subsequent statements that use the variable report this error. If the function declaration statement has an error, the same problem will be raised.

(7) Error C2086: ' xxxx ': redefinition

Item No: C2374
"XXXX" repeat the statement.
Error Analysis:
The variable "XXXX" has been defined multiple times in the same scope. Check every definition of "xxxx", keep only one, or change the quantity name.

(8) Error C2374: ' xxxx ': redefinition; Multiple initialization

Item No: C2374
"XXXX" repeated the declaration, multiple initialization.
Error Analysis:
The variable "XXXX" has been defined multiple times in the same scope and has been initialized multiple times. Check every definition of "xxxx", keep only one, or change the quantity name.

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

Item No: C2143
A semicolon is missing before the (marker) "XXXX".
Error Analysis:
This is the most common misstatement of VC6 's compilation period, when this error occurs, often the statement is not error, but its last sentence has been wrong. In fact, a more appropriate approach is that the compiler report lacks a semicolon at the end of the previous statement. Many of the errors in the previous statement cause the compiler to report this error:

1. A semicolon is really missing at the end of the previous sentence. Then you can fill it up.
2. The previous statement is incomplete, or there is an obvious grammatical error, or the last sentence cannot be counted (sometimes accidentally pressed to the keyboard).
3. If the statement that the error occurred is the first line of the CPP file, check that there are no errors in this file, but it contains a header file in double quotes, check the header file, and there may be an error on the tail of the header file.

(a) Error C4716: ' xxx ': Must return a value

Item No: C4716
Literal translation: "XXX" must return a value.
Error Analysis:
The function declares a return value (not void), but the return value is forgotten in the function implementation. Either the function does not have a return value, modify its return value type to void, or return the appropriate value before the function ends.

(one) Warning C4508: ' main ': function should return a value; ' void ' return type assumed

Item No: C4508
The main function should return a value; void return value type is assumed.
Error Analysis:

1. Function should have return value, declare function should indicate the type of return value, there is no return value, the function return value should be declared as void. If you do not declare the type of the function return value, the system defaults to integer int. The error estimate here is that there is no return value statement in the main function, and the main function either does not declare the type of its return value or declares it.
The 2.warning type of error is a warning error, which means that the program can still be successfully compiled, linked, but may be problematic and risky.

(a) Warning c4700:local variable ' xxx ' used without having been initialized

Item No: C4700
Warning local variable "xxx" is not initialized before use.
Error Analysis:
This is a common error for beginners, such as the following section of the program will cause such a warning, and the program does have a problem, it should be modified, although the compilation, link can be successful-if not modified, the value of x in the end is how many can not be determined, is random, to determine whether it is the same as 3 meaningless, in bad luck, may be running on the debugger's machine, the result appears to be correct, but after the replacement of the computer and then run, the result is wrong, beginners often confused.
int x;
if (x==3) printf ("Hello");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.