“不命名类型"即使我在分配值之前就声明了错误 [英] "Does not name a type" error even though I declare right before assigning the values

查看:344
本文介绍了“不命名类型"即使我在分配值之前就声明了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将问题简化为以下代码:

I have slimmed my problem down to the following code:

#include <iostream>

using namespace std;

struct hello
{
    int array[4];
    array[0] = 1;
    array[1] = 2;
    array[2] = 3;
    array[3] = 4;
};

当我对此进行编译时,在分配值的每一行上仍然出现数组未命名类型"错误.AFAIK,即使我在分配的正上方声明了数组,当将变量声明为nto时也会导致此错误.

And when I compile this I still get the 'array does not name a type' error, on every line where I assign a value. AFAIK this error is caused when a variable is nto declared, even though I declare array right above the assignment.

推荐答案

赋值声明,例如array [0] = 0;无法进入结构定义,需要进入可执行代码块,例如函数,构造函数或类似代码.

Assignment statements like array[0] = 0; cannot go into the struct definition, the need to go into an executable block of code like a function, a constructor or similar.

struct hello
{
    int array[4];
    hello(){
        array[0] = 1;
        array[1] = 2;
        array[2] = 3;
        array[3] = 4;
    }
};

这篇关于“不命名类型"即使我在分配值之前就声明了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆