派生自C结构 [英] deriving from a C struct

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

问题描述




我想了解更多关于从现有C结构派生的信息。

让我说我厌倦了总是写作相同的代码如下所示:


MYSTRUCT foo;

memset(& foo,0,sizeof(MYSTRUCT));

foo.cbSize = sizeof(MYSTRUCT);

SendMessage(xxx,WM_MYSTRUTC,&(foo),0);


所以我想做类似的事情

struct MYSTRUCT_Helper:public MYSTRUCT

{

MYSTRUCT_Helper()

{

memset(this,0,sizeof(MYSTRUCT));

this-> foo.cbSize = sizeof(MYSTRUCT);


} < br $>
}


之后


MYSTRUCT_Helper betterFoo;

SendMessage(xxx,WM_MYSTRUTC ,&n;(betterFoo),0);


我可以这样做吗?

Hi,

I would like more info about deriving from an existing C struct.
Let''s say I am fed up with always writing the same code shown below :

MYSTRUCT foo;
memset( &foo, 0, sizeof(MYSTRUCT) );
foo.cbSize = sizeof(MYSTRUCT);
SendMessage(xxx, WM_MYSTRUTC, &(foo), 0);

So I would like to do something like
struct MYSTRUCT_Helper : public MYSTRUCT
{
MYSTRUCT_Helper()
{
memset( this, 0, sizeof(MYSTRUCT) );
this->foo.cbSize = sizeof(MYSTRUCT);

}
}

and after

MYSTRUCT_Helper betterFoo;
SendMessage(xxx, WM_MYSTRUTC, &(betterFoo), 0);


Can I do something like that ?

推荐答案

Mosfetaécrit:
Mosfet a écrit :




我会李更多关于从现有C结构派生的信息。

让我说我厌倦了总是编写如下所示的相同代码:


MYSTRUCT foo;

memset(& foo,0,sizeof(MYSTRUCT));

foo.cbSize = sizeof(MYSTRUCT);

SendMessage (xxx,WM_MYSTRUTC,&(foo),0);


所以我想做类似的事情


struct MYSTRUCT_Helper:public MYSTRUCT

{

MYSTRUCT_Helper()

{

memset(this,0,sizeof(MYSTRUCT));

this-> foo.cbSize = sizeof(MYSTRUCT);


}

}

之后


MYSTRUCT_Helper betterFoo;

SendMessage(xxx,WM_MYSTRUTC,&(betterFoo),0);



我可以这样做吗?
Hi,

I would like more info about deriving from an existing C struct.
Let''s say I am fed up with always writing the same code shown below :

MYSTRUCT foo;
memset( &foo, 0, sizeof(MYSTRUCT) );
foo.cbSize = sizeof(MYSTRUCT);
SendMessage(xxx, WM_MYSTRUTC, &(foo), 0);

So I would like to do something like
struct MYSTRUCT_Helper : public MYSTRUCT
{
MYSTRUCT_Helper()
{
memset( this, 0, sizeof(MYSTRUCT) );
this->foo.cbSize = sizeof(MYSTRUCT);

}
}

and after

MYSTRUCT_Helper betterFoo;
SendMessage(xxx, WM_MYSTRUTC, &(betterFoo), 0);


Can I do something like that ?



如果我在里面添加一个方法它还能用吗?

and if I add a method inside will it still work ?


Mosfet写道:
Mosfet wrote:

Mosfetaécrit:
Mosfet a écrit :

>

我想了解更多信息源自现有的C结构。
让我说我厌倦了总是编写如下所示的相同代码:

MYSTRUCT foo;
memset(& foo, 0,sizeof(MYSTRUCT));
>Hi,

I would like more info about deriving from an existing C struct.
Let''s say I am fed up with always writing the same code shown below :

MYSTRUCT foo;
memset( &foo, 0, sizeof(MYSTRUCT) );



一般来说,C ++中的坏主意。最好放弃这种习惯。明确初始化你的聚合物要好得多:


MYSTRUCT foo = {};

Bad idea in C++, in general. Better to drop that habit. It is much
better to explicitly initialise your aggregate:

MYSTRUCT foo = {};


> foo.cbSize = sizeof(MYSTRUCT);
SendMessage(xxx,WM_MYSTRUTC,&(foo),0);
>foo.cbSize = sizeof(MYSTRUCT);
SendMessage(xxx, WM_MYSTRUTC, &(foo), 0);



无论如何......

Whatever that does...


>>
所以我想做类似

struct MYSTRUCT_Helper:public MYSTRUCT
>>
So I would like to do something like
struct MYSTRUCT_Helper : public MYSTRUCT



' '公共'是多余的。不过可以提醒。

''public'' is superfluous. OK for a reminder, though.


> {
MYSTRUCT_Helper()
{
memset(this,0,sizeof(MYSTRUCT));
this-> foo.cbSize = sizeof(MYSTRUCT);

}
}
和之后

MYSTRUCT_Helper betterFoo;
SendMessage(xxx,WM_MYSTRUTC,&(betterFoo),0);


我能做点什么吗那个?
>{
MYSTRUCT_Helper()
{
memset( this, 0, sizeof(MYSTRUCT) );
this->foo.cbSize = sizeof(MYSTRUCT);

}
}

and after

MYSTRUCT_Helper betterFoo;
SendMessage(xxx, WM_MYSTRUTC, &(betterFoo), 0);


Can I do something like that ?



你可以,但是忘记对象(或其中任何一个/ b
)是一个糟糕的想法(tm) part)到0,特别是在它自己的构造函数中。

You can, but it''s a BAD IDEA(tm) to memset the object (or any of
its parts) to 0, especially in its own constructor.


如果我在里面添加一个方法它还能工作吗?
and if I add a method inside will it still work ?



是的,我想它会起作用。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

Yes, I suppose it will work.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask




" Victor Bazarov" < v。******** @ comAcast.netwrote in message

news:f2 ********** @ news.datemas.de ...

"Victor Bazarov" <v.********@comAcast.netwrote in message
news:f2**********@news.datemas.de...

你可以,但是将对象(或其任何部分的b / b)中的对象(或其任何部分)设置为0是一个不好的想法(特别是),尤其是在它自己的构造函数中。
You can, but it''s a BAD IDEA(tm) to memset the object (or any of
its parts) to 0, especially in its own constructor.



你的意思是,与使用初始化列表或在构造函数中明确设置成员

零相反,对吧? IOW,你有问题

memset而不是归零(?)。


John

You mean, as opposed to using an initializer list or setting the members to
zero explicitly inside the constructor, right? IOW, you have issue with the
memset and not the zeroing (?).

John


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

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