Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
int *__vfptr; // 2 underscores

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.
Posted
Updated 1-Dec-10 0:13am
v2
Comments
CPallini 1-Dec-10 6:01am    
Pardon the silly question, but: "why should you give such a name to the data member?"
Sauro Viti 1-Dec-10 6:16am    
Why do you want to modify the vtable of an object? Sincerely, I'm not able to imagine what does the possibilities are...
maQueueBex 1-Dec-10 6:37am    
@CPallini - I did that on purpose.

@Sauro Viti -
Redirecting (the already redirected)virtual function calls at run time?
CPallini 1-Dec-10 15:35pm    
Still I cannot see the usefulness of fooling the compiler this way.

1 solution

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.
 
Share this answer
 
Comments
maQueueBex 1-Dec-10 22:45pm    
#include <iostream>

int main()
{
int __ = 1;
__ = 5;
}

I tried this, and it seems to work like a normal var! Even __a or anything.
Is it like undefined behavior when we use this? Compiler may or may not mess it up?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900