|
-
May 16th, 2009, 12:39 PM
#2
Re: sizeof() on derived class objects
 Originally Posted by newHere
actually, I am trying to write a fun() that can take the base class (Base) object or any derived classes (A, B) objects and prints the correct size of the pass in object, which I failed in the above code.
sizeof is an operator whose result is determined at compile time. The object that the base reference refers to can vary at run time. As such, you are asking for the impossible (except in special cases, or possibly by overloading, which may not be quite what you want).
By the way, get rid of the semi-colons after your function definitions. Note that the global main function should return an int, not void.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|