c++结构数组 - "This declaration has no storage class or type specifier"

标签 c++ arrays visual-c++ struct

我在处理结构数组时遇到问题。这是我生成 2 条红色错误行的代码。

    struct frequents
{
    int count;
    char letter;
};

frequents testArray[2];
testArray[1].letter = 'v';   

错误出现在具有声明错误的 testArray 下和“.”下其中提到它需要一个“;”。

最佳答案

这是一个 statement :

testArray[1].letter = 'v';

语句将在函数(函数体)内执行,而不是像现在这样在某个任意的全局命名空间中执行。在主程序中移动您的语句 entry point function , 一个 lambda ,一个独立的functionclass成员函数体。

或者,使用 aggregate initialization初始化你的数组:

frequents testArray[2] = {{ 1, 'a' }, { 2, 'b' }};

或者没有额外的大括号:

frequents testArray[2] = { 1, 'a', 2, 'b' };

关于c++结构数组 - "This declaration has no storage class or type specifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51171751/

相关文章:

c++ - 未知包装 nar - nar-maven-plugin

c++ - Dijkstra 算法 - 初始化节点距离

c - 使用 C99 和 C11 时的效率问题。

windows - 是否可以从 IFileDialog 中删除/隐藏打开按钮

c++ - Boost::Python 前向声明 boost::python::object 抛出 python TypeError

c# - 如何将 std::string& SWIG 转换为 C# 引用字符串

javascript - 仅获取 json 数组中的第 4 个元素

ios - 找不到接受提供的参数的重载 'init'

php - php中通过POST多个输入同名

windows - 可能使用提升的权限创建的日志文件