Y
ypjofficial
Hello All,
I have read in many c++ literature that vtable is nothing but an array
of pointer to virtual functions inside a class.And the class where the
virtual function/s are declared stores the vfptr i.e the pointer to
vtable internally.
What confuses me is
if vtable is an array of pointer to virtual functions then as per the
properties of the array all the entries inside the array must be
same.i.e all the pointers should be of similar type.and this will put
restriction on the declaration of the virtual functions as they must
have same singnature as per my point.
eg. class base
{
public:
virtual void fun(int,int);
virutal int fun2(char);
};
now according to the definition of vtable(i.e array of pointers to
virtual functions)
what will be the syntax for the array? as single array can't hold
entries with different datatypes.
the pointer to first virtual function is something like
void (base::*fptr1)(int,int) and for second its like
int (base::*fptr2)(char)
how come a single array like vtable will stored these two totally
different entires?
but a structure can stores mulitple datatypes.
So is Vtable a structure or an array? if its array then can anyone give
me its definition?
Thanks and regards,
Yogesh Joshi
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
I have read in many c++ literature that vtable is nothing but an array
of pointer to virtual functions inside a class.And the class where the
virtual function/s are declared stores the vfptr i.e the pointer to
vtable internally.
What confuses me is
if vtable is an array of pointer to virtual functions then as per the
properties of the array all the entries inside the array must be
same.i.e all the pointers should be of similar type.and this will put
restriction on the declaration of the virtual functions as they must
have same singnature as per my point.
eg. class base
{
public:
virtual void fun(int,int);
virutal int fun2(char);
};
now according to the definition of vtable(i.e array of pointers to
virtual functions)
what will be the syntax for the array? as single array can't hold
entries with different datatypes.
the pointer to first virtual function is something like
void (base::*fptr1)(int,int) and for second its like
int (base::*fptr2)(char)
how come a single array like vtable will stored these two totally
different entires?
but a structure can stores mulitple datatypes.
So is Vtable a structure or an array? if its array then can anyone give
me its definition?
Thanks and regards,
Yogesh Joshi
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]