结构和不断的成员 [英] structure and constant memebers

查看:62
本文介绍了结构和不断的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在所有专家中,

i有一个具有常数成员的结构,例如下面给出的结构:


typedef struct {

const int cbcode;

int cberror;

} xtsetplatestaterec;


现在在我的函数中我想创建一个基于堆栈的对象:


void CreateObjectAndUseIt {

xtsetplatestaterec plate;

xtsetplatestaterec plate2 = {0,0};

}

现在这个函数在编译

vc ++ 6.0时给出了编译错误,因为

cbcode memeber是一个不变。错误是

错误C2512:''xtsetbleedvaluesrec'':没有合适的默认构造函数

可用

错误C2552:''tmpsetplatestaterec'':非聚合不能用初始化列表初始化



任何人都可以解释我可以做些什么来创建

的实例堆栈中的这些对象???

谢谢

rt

hi all experts,
i have a structure with the constant memebers such as one given below:

typedef struct {
const int cbcode;
int cberror;
} xtsetplatestaterec;

now in my function i want to create a stack based object for the same:

void CreateObjectAndUseIt{
xtsetplatestaterec plate;
xtsetplatestaterec plate2 = {0 , 0};
}
now this function is giving the compilation errors while compiling on
vc++ 6.0 since the
cbcode memeber is a constant. the error is
error C2512: ''xtsetbleedvaluesrec'' : no appropriate default constructor
available
error C2552: ''tmpsetplatestaterec'' : non-aggregates cannot be
initialized with initializer list

can anybody plz explain me what could be done to create instances of
these objects on stack ???
thanks
rt

推荐答案


ra ************ @ gmail.com ?????

ra************@gmail.com ???é?????
嗨所有专家,

i有一个结构,其中有一个常数,例如下面给出的一个:
typedef struct {
const int cbcode;
int cberror;
} xtsetplatestaterec;
现在在我的函数中我想创建一个基于堆栈的对象同样的:

void CreateObjectAndUseIt {
xtsetplatestaterec plate;
xtsetplatestat erec plate2 = {0,0};
}

现在这个函数在编译
vc ++ 6.0时给出了编译错误,因为
cbcode memeber是一个常量。错误是

错误C2512:''xtsetbleedvaluesrec'':没有合适的默认构造函数
错误C2552:''tmpsetplatestaterec'':非聚合不能
用初始化列表初始化

任何人都可以解释一下如何在堆栈上创建这些对象的实例???

谢谢
rt
hi all experts,
i have a structure with the constant memebers such as one given below:

typedef struct {
const int cbcode;
int cberror;
} xtsetplatestaterec;

now in my function i want to create a stack based object for the same:

void CreateObjectAndUseIt{
xtsetplatestaterec plate;
xtsetplatestaterec plate2 = {0 , 0};
}
now this function is giving the compilation errors while compiling on
vc++ 6.0 since the
cbcode memeber is a constant. the error is
error C2512: ''xtsetbleedvaluesrec'' : no appropriate default constructor
available
error C2552: ''tmpsetplatestaterec'' : non-aggregates cannot be
initialized with initializer list

can anybody plz explain me what could be done to create instances of
these objects on stack ???
thanks
rt



为什么你在那里使用const,也许你可以这样写:


typedef struct {

const int cbcode = 0;

int cberror;

} xtsetplatestaterec;


why you use const there,maybe you can write like this :

typedef struct {
const int cbcode=0;
int cberror;
} xtsetplatestaterec;


ra ************ @ gmail.com 写道:
所有专家,

i有一个结构,其中包括下面给出的常数成员:

typedef struct {
const int cbcode;
int cberror;
} xtsetplatestaterec;
现在在我的函数中我想创建一个堆栈库对象相同:

void CreateObjectAndUseIt {
xtsetplatestaterec plate;
xtsetplatestaterec plate2 = {0,0};
}


以上与基于堆栈的对象无关。你使用局部变量(相当合法地使用b $ b)。没有迹象表明您使用了

堆栈。


现在这个函数在编译时给出编译错误
vc ++ 6.0因为cbcode memeber是一个常数。错误是

错误C2512:''xtsetbleedvaluesrec'':没有合适的默认构造函数
可用


上面的错误消息提示您使用的是C ++编译器。

错误C2552:''tmpsetplatestaterec'':非聚合不能用初始化列表初始化


因为我们可以''看tmpsetplatestaterec或者你想要的是什么?b $ b初始化,你不可能知道你做错了什么。

可以任何人PLZ解释我可以做些什么来创建实例这些对象在堆栈上???
hi all experts,
i have a structure with the constant memebers such as one given below:

typedef struct {
const int cbcode;
int cberror;
} xtsetplatestaterec;

now in my function i want to create a stack based object for the same:

void CreateObjectAndUseIt{
xtsetplatestaterec plate;
xtsetplatestaterec plate2 = {0 , 0};
}
The above has nothing to do with "stack based object"s. You are (quite
legally) using local variables. There is not a sign of your use of a
stack in sight.

now this function is giving the compilation errors while compiling on
vc++ 6.0 since the
cbcode memeber is a constant. the error is
error C2512: ''xtsetbleedvaluesrec'' : no appropriate default constructor
available
The above error message suggests you are using a C++ compiler.
error C2552: ''tmpsetplatestaterec'' : non-aggregates cannot be
initialized with initializer list
Since we can''t see tmpsetplatestaterec or what you are trying to
initialize, it is impossible to tell what you are doing wrong.
can anybody plz explain me what could be done to create instances of
these objects on stack ???




如果您使用的代码出现问题(而且您感到困惑

带有堆栈上的对象的局部变量,这意味着在C中没有任何内容,除非您创建和维护堆栈,然后停止使用C ++编译器。 C和

C ++是不同的语言;编译C代码就好像它是C ++一样

要求麻烦。


如果你实际上想要修改(而不是初始化)const

结构成员,然后不要。要么不修改会员,要么删除''const'',这毕竟是谎言。



If the code you are using is giving a problem (and you are confusing
local variables with "objects on stack", which means nothing in C unless
you create and maintain a stack), then stop using a C++ compiler. C and
C++ are different languages; compiling C code as if it were C++ is
asking for trouble.

If you are actually trying to modify (rather than to initialize) a const
member of a structure, then don''t. Either don''t modify the member or
remove the ''const'' which, after all, is a lie.


us ****** @ gmail.com 写道:
us******@gmail.com wrote:
为什么你用const那里,也许你可以这样写:

typedef struct {
const int cbcode = 0;
int cberror;
} xtsetplatestaterec;
why you use const there,maybe you can write like this :

typedef struct {
const int cbcode=0;
int cberror;
} xtsetplatestaterec;




为什么你会这么愚蠢的想法?



Why would you think such a foolish thing?


这篇关于结构和不断的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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