错误:使用“ {...}”初始化预期聚合对象-C ++ [英] error: initialization with "{...}" expected for aggregate object - c++

查看:1020
本文介绍了错误:使用“ {...}”初始化预期聚合对象-C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

struct test
{
    unsigned int test1;
    unsigned char test2[4096];
    unsigned int test3;
} foo

struct foobar
{
unsigned char data[4096];
}

如果我要访问该结构,请说foo.test1,foo。 test2 [4096]等。但是,当我希望以以下方式返回foo.test2中存在的数据时,

if i want to access the struct, i say foo.test1, foo.test2[4096], etc.. however, when I wish to return the data present in foo.test2 in the following manner

pac.datafoo = foo.test2[4096];

unsigned char data[4096] =  pac.datafoo;

这是我得到的错误:

error: initialization with "{...}" expected for aggregate object


$ b $进行 {...}初始化b

我在做什么错误?

what is the mistake i'm doing?

推荐答案

您需要学习数组初始化方法。

You need to learn the array initialization method. It's NOT simply assigned as the single variable.

一些示例:

int arrayone[3] = {0}; // assign all items with 0

int arraytwo[3] = {1, 2, 3 }; // assign each item with 1, 2 and 3

int arraythree[3]; // assign arraythree with arraytwo
for (int i = 0; i < 3; ++i) {
    arraythree[i] = arraytwo[i];
}

这篇关于错误:使用“ {...}”初始化预期聚合对象-C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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