类方法不如C函数强健? [英] Class method less robust than C function?

查看:43
本文介绍了类方法不如C函数强健?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GUI消息传递并注意到MFC封装了C ++类成员函数内部的消息循环。这个

在某种程度上不如调用消息循环那么健壮吗

函数在main中? (它只是感觉对我不对。)


示例1:


类MyProg

{

public:


void Run()

{

Msg m;

而(GetMsg(m))

DispatchMsg(m);

}

};


int main()

{

MyProg p;

p.Run(); //只是觉得在课堂上完成整个编程是不对的

func

返回1;

}


示例2:


int main()

{

Msg m;

而(GetMsg(m))

DispatchMsg(m);

返回1;

}


我在想的是一个类是否比同等的C代码更可能被损坏了.b $ b。也许如果C ++一路走来的话。并且消除了

C main函数我会用类封装的消息感觉更好

循环。

尽管如此,甚至C ++喜欢程序主,而不是某种类型的

程序。课程。


请随意添加关于切向但相关主题的评论




Tony

I''m working with GUI messaging and note that MFC encapsulates
the message loop inside of a C++ class member function. Is this
somehow inherently less robust than calling the message loop
functions within main? (It just doesn''t "feel" right to me).

Example 1:

class MyProg
{
public:

void Run()
{
Msg m;
while(GetMsg(m))
DispatchMsg(m);
}
};

int main()
{
MyProg p;
p.Run(); // just doesn''t feel right to run the whole prog in a class
func
return 1;
}

Example 2:

int main()
{
Msg m;
while(GetMsg(m))
DispatchMsg(m);
return 1;
}

What I''m thinking about is whether a class is more likely to be corrupted
than the equivalent C code. Perhaps if C++ went "all the way" and eliminated
the C main function I''d feel better with the class-encapsulated message
loop.
As it is though, even C++ likes procedural main rather than some kind of
"program" class.

Please feel free to add any comments on tangential but associated topics
also.

Tony

推荐答案

Tony写道:
Tony wrote:

我正在使用GUI消息传递并注意到MFC封装了C ++类成员函数内部消息循环的
。这个

在某种程度上不如调用消息循环那么健壮吗

函数在main中? (它只是感觉对我不对。)
I''m working with GUI messaging and note that MFC encapsulates
the message loop inside of a C++ class member function. Is this
somehow inherently less robust than calling the message loop
functions within main? (It just doesn''t "feel" right to me).



MFC中的任何内容都没有感觉到吗?

Does anything in MFC feel right?


>

我在想的是一个班级是否比同等的C代码更可能被损坏

。也许如果C ++一路走来的话。并消除了

C main函数我会用类封装的消息感觉更好

循环。
>
What I''m thinking about is whether a class is more likely to be corrupted
than the equivalent C code. Perhaps if C++ went "all the way" and eliminated
the C main function I''d feel better with the class-encapsulated message
loop.



腐败了什么?


-

Ian Collins。

Corrupted by what?

--
Ian Collins.




Tony写道:

Tony wrote:

我正在使用GUI消息传递并注意到MFC封装了消息循环内部的消息循环C ++类成员函数。这个

在某种程度上不如调用消息循环那么健壮吗

函数在main中? (它并没有感觉对我来说是正确的)。
I''m working with GUI messaging and note that MFC encapsulates
the message loop inside of a C++ class member function. Is this
somehow inherently less robust than calling the message loop
functions within main? (It just doesn''t "feel" right to me).



这里的MFC不在话题,也与消息传递有关。

MFC类也不是C ++类。经验法则是:如果它只在Windows中运行,或者仅在Linux或任何操作系统中运行,那么它的主题就在这里。

此处的语言隐藏是C ++标准图书馆。


请大家帮个忙,考虑使用WTL。 MFC应该拥有什么?b $ b首先。

它支持模板和继承。太糟糕了,MS对它的支持下降了,因为它与MFC相比有所下降。最后我查了一下,MS

在双重许可下将它汇给OpenSource。
http://en.wikipedia.org/wiki/Windows_Template_Library


>

示例1:


class MyProg

{

public:


void Run ()

{

Msg m;

while(GetMsg(m))

DispatchMsg(m);

}

};


int main()

{

MyProg p;

p.Run(); //只是觉得在课堂上完成整个编程是不对的

func

返回1;

}


示例2:


int main()

{

Msg m;

而(GetMsg(m))

DispatchMsg(m);

返回1;

}


我在想的是一个类是否比同等的C代码更可能被损坏了.b $ b。也许如果C ++一路走来的话。并且消除了

C main函数我会用类封装的消息感觉更好

循环。

尽管如此,甚至C ++喜欢程序主,而不是某种类型的

程序。课程。


请随意添加关于切向但相关主题的任何评论




Tony
>
Example 1:

class MyProg
{
public:

void Run()
{
Msg m;
while(GetMsg(m))
DispatchMsg(m);
}
};

int main()
{
MyProg p;
p.Run(); // just doesn''t feel right to run the whole prog in a class
func
return 1;
}

Example 2:

int main()
{
Msg m;
while(GetMsg(m))
DispatchMsg(m);
return 1;
}

What I''m thinking about is whether a class is more likely to be corrupted
than the equivalent C code. Perhaps if C++ went "all the way" and eliminated
the C main function I''d feel better with the class-encapsulated message
loop.
As it is though, even C++ likes procedural main rather than some kind of
"program" class.

Please feel free to add any comments on tangential but associated topics
also.

Tony




" Salt_Peter" < pj ***** @ yahoo.comwrote in message

news:11 ********************* @ e3g2000cwe.googlegrou ps.com ...

"Salt_Peter" <pj*****@yahoo.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...

>

Tony写道:
>
Tony wrote:

>我正在使用GUI消息传递并注意到MFC将消息循环封装在C ++类成员函数中。这在某种程度上比在main中调用消息循环
函数本质上更不健壮吗? (它并没有感觉对我来说是正确的)。
>I''m working with GUI messaging and note that MFC encapsulates
the message loop inside of a C++ class member function. Is this
somehow inherently less robust than calling the message loop
functions within main? (It just doesn''t "feel" right to me).



MFC不在这里,也与消息传递有关。

MFC类也不是C ++类。经验法则是:如果它只在Windows中运行,或者仅在Linux或任何操作系统中运行,那么它的主题就在这里。

此处的语言隐藏是C ++标准图书馆。


MFC is off topic here as well as anything to do with "messaging". An
MFC class is not a C++ class either. The rule of thumb is: if it only
runs in Windows or only in Linux or whatever OS, its off topic here.
The language dealth with here is the C++ standard library.



这根本不是MFC的问题。 MFC就是一个例子。你给了上下文的原始帖子太多了。


Tony

It wasn''t an MFC question at all. MFC was just the example. You clipped
too much of the original post that gave the context.

Tony


这篇关于类方法不如C函数强健?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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