繁体   English   中英

错误:使用“{…}”初始化聚合对象 - C++

[英]error: initialization with “{…}” expected for aggregate object - 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 中存在的数据时

pac.datafoo = foo.test2[4096];

unsigned char data[4096] =  pac.datafoo;

这是我得到的错误:

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

我在做什么错误?

你需要学习数组初始化方法。 它不是简单地分配为单个变量。

一些例子:

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];
}

添加 ”;” 在结构的末尾。

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

struct foobar
{
unsigned char data[4096];
} ;
unsigned char * data;

  data = pac.datafoo;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM