7

嗨,我正在尝试定义一个名为 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;
}

我不断收到编译器错误说:

错误 1 ​​错误 C4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持 default-int c:\users\naqvi-home\documents\justit\c++\w1\cp1\list0304.cpp 8 1 ConsoleApplication3

谢谢

4

3 回答 3

13

和你的无关typedef。问题是您没有给出返回类型main

int main()
{
  // ...
}

函数必须有返回类型。该main函数必须返回int

于 2013-03-03T13:59:33.047 回答
3

通过谷歌搜索错误代码,您可以轻松查找错误的解释。例如,谷歌搜索“C4430”会带你到这里。正如其他人所说,原因是您没有声明main函数的返回类型。

于 2013-03-03T14:07:25.523 回答
2

我不相信您需要inttypedef 中的额外内容,我从内存中认为 unsigned short (默认情况下)是一个 int。

于 2013-03-03T14:00:28.717 回答