C++ 编译器错误 c4430“c++ 不支持默认 int”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15186416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ compiler error c4430 "c++ doesnt support default int"
提问by Rehan Naqvi
Hi im trying to define an alias called USHORT.
嗨,我正在尝试定义一个名为 USHORT 的别名。
// *****************
// Demonstrates typedef keyword
#include <iostream>
typedef unsigned short int USHORT; // typedef defined
main()
{
USHORT Width = 5;
USHORT Length;
Length = 10;
USHORT Area = Width * Length;
std::cout << "Width:" << Width << "\n";
std::cout << "Length: " << Length << std::endl;
std::cout << "Area: " << Area;
}
I keep getting a compiler error saying:
我不断收到编译器错误说:
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\naqvi-home\documents\justit\c++\w1\cp1\list0304.cpp 8 1 ConsoleApplication3
错误 1 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int c:\users\naqvi-home\documents\justit\c++\w1\cp1\list0304.cpp 8 1 ConsoleApplication3
Thanks
谢谢
Ray
射线
回答by Joseph Mansfield
It has nothing to do with your typedef
. The problem is that you haven't given a return type for main
:
跟你的没有关系typedef
。问题是你没有给出返回类型main
:
int main()
{
// ...
}
A function must have a return type. The main
function must return int
.
一个函数必须有一个返回类型。该main
函数必须返回int
。
回答by TheLazyChap
I don't believe you need the extra int
in the typedef, I thought from memory unsigned short (by default) is an int.
我不相信你int
在 typedef 中需要额外的,我认为从内存中 unsigned short (默认情况下)是一个 int。
回答by Zdeslav Vojkovic
You can easily look up the explanation for the error, by googling the error code. E.g. googling for 'C4430' would lead you here. The reason is, as others have stated, that you haven't declared the return type for main
function.
您可以通过谷歌搜索错误代码轻松查找错误的解释。例如,在谷歌上搜索“C4430”会带你到这里。原因是,正如其他人所说,您尚未声明main
函数的返回类型。