可以比较 RUNTIME_CLASS() 宏返回的指针吗?

发布于 2024-09-05 13:12:25 字数 493 浏览 5 评论 0原文

我有一个函数,它需要 CRuntimeClass 指针列表来设置视图。如果使用已设置的相同类的列表调用该函数,我想返回而不执行任何操作。保存指针值并在下一次调用时比较它们当前正在工作,但我想验证这是合法的事情,而不是偶然发生的事情。也许我的 doc-search-fu 缺少,但我找不到任何地方可以保证从给定类的 RUNTIME_CLASS() 宏返回的指针值在程序的生命周期中是相同的。我能找到的最接近的是 CObject::GetRuntimeClass( )

每个 CObject 派生类都有一个 CRuntimeClass 结构。

这意味着指针值不应更改,但并未明确说明。有人对此有更具体的了解吗?或者有更好的方法来比较 CRuntimeClasses 吗?

I've got a function that takes a list of CRuntimeClass pointers in order to setup a view. I'd like to return without doing anything if the function is called with a list of the same classes that are already setup. Saving the pointer values and comparing them on the next call is currently working, but I want to verify that that's a legal thing to do, and not something that just happens to work. Maybe my doc-search-fu is lacking, but I can't find anywhere that guarantees the pointer value returned from the RUNTIME_CLASS() macro for a given class will be the same for the life of the program. The closest I could find is in the docs for CObject::GetRuntimeClass():

There is one CRuntimeClass structure for each CObject-derived class.

That implies that the pointer value shouldn't change, but doesn't exactly state it. Does anyone have something a bit more concrete on that? Or is there a better way to compare the CRuntimeClasses?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

燃情 2024-09-12 13:12:25

尽管有可能,但没有记录这样的保证。您应该使用 CObject::IsKindOf()。

No such guarantee is documented, albeit that it is likely. You are supposed to use CObject::IsKindOf().

难得心□动 2024-09-12 13:12:25

查看 afx.h 并进行一些调试表明 RUNTIME_CLASS() 返回一个指向静态成员的指针:static CRuntimeClass class##class_name (可以在 DECLARE_DYNAMIC(class_name) 宏的定义中看到)。

由于该成员是静态的,因此指向它的指针在运行时不会改变。换句话说,static 是您的保证。

Taking a peek at afx.h plus a little of debugging shows that RUNTIME_CLASS() returns a pointer to a static member: static CRuntimeClass class##class_name (as it can be seen in the definition of DECLARE_DYNAMIC(class_name) macro).

As the member is static, the pointer to it does not change during runtime. In other words static is your guarantee.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文