shuisheng wrote: [top posting corrected]
>Victor Bazarov wrote:
shuisheng wrote:
I am wondering is it possible to get a variable's type and size in
code.
Yes. What are you trying to accomplish?
For example, I have a base class Shape and its derived class Sphere and
Cube. I use the Shape pointer substantialize a Sphere. How can I know
it is Sphere rather than Cube?
a) Please don't top post. Had you read Victor's signature, you would have
known that top posting will only get your post ignored. His sentiments are
shared by most regulars in this group. Top posting is considered poor form
around these parts. It's a cultural thing.
b) You want to read up on dynamic_cast.
c) If you find yourself wanting to test whether a Shape* actually points to
a cube, you are usually in a state of sin, i.e., your design is somewhat
broken. Ideally, you should never need to do that. The interface of Shape
should be flexible enough so that all specializations can go about all
their businesses using the Shape interface.
Best
Kai-Uwe Bux