__VFPTR为会员 [英] __VFPTR as a member

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

问题描述


我对C ++比较陌生(例如6个月的经验).
我正在阅读有关虚拟函数的vtables.

我创建了一个具有以下成员的课程:

Hi,
I''m relatively new to C++ (like 6 months exp).
I was reading about the vtables for Virtual Functions.

I created a class with a member as:

int *__vfptr; // 2 underscores


令人惊讶的是,当我调试应用程序时,它被链接到vtable指针!
PS:我们需要在课堂上至少有一个虚函数.

但是,它就像一个函数指针数组,它是const.

如果我在此上使用const_cast-它似乎不起作用:(
无论如何,我可以删除此常量吗?

试想一下可能性..; P

我在XP上使用VS2008.


Surprisingly, when I debug the app, it gets linked to the vtable pointer!
PS: We need to have at least one virtual function in the class.

But, its like an array of function pointers and it''s const.

If I use const_cast on this - it doesn''t seem to work :(
Is there anyway I could remove this constness?

Just imagine the possibilities.. ;P

Me using VS2008 on XP.

推荐答案

C和C ++语言标准保留的标识符以两个下划线或一个下划线开头,后跟一个大写字母,用于编译器实现. .

因此,__vfptr不受变量的常规"规则约束.
The C and C++ language standards reserve identifiers starting with either two underscores or an underscore followed by an upper-case letter for the compiler implementation.

Therefore __vfptr won''t be subject to the "normal" rules for variables.


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

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