virtual revisited

P

puzzlecracker

small question: virutal functions, regular fucntions and inline
functions take the same space (ex: 4 bytes or 8 bytes 32 and 64 bits
respectively)? According to alignement rules: compiler is tring to fit
as many variable (data types) as possible in each block for as long as
it fits entirely or else adds padding... is that the correct way of
thinking?


also, is function always represented as a pointer in a struct and
occupies its size?


Thanks...
 
J

Jonathan Turkanis

puzzlecracker said:
small question: virutal functions, regular fucntions and inline
functions take the same space (ex: 4 bytes or 8 bytes 32 and 64 bits
respectively)? According to alignement rules: compiler is tring to fit
as many variable (data types) as possible in each block for as long as
it fits entirely or else adds padding... is that the correct way of
thinking?
also, is function always represented as a pointer in a struct and
occupies its size?

It sounds like you think member functions take up space in an class instance
like data members. This is certainly not required by the standard, and would be
a waste of time and space.

Virtual functions generally do increase the size of class instances. But there
is typically an extra level of indirection; they are not stored as pointers
within a class instance.
Thanks...

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top