Re: CreateInstance

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks Alex,


The `sizeof' operator never yields 0, even for an empty class.

"sizeof Operator"
http://msdn2.microsoft.com/en-us/library/4s7x1k91.aspx

I have read the link and I found as you mentioned sizeof never results in 0
as result. How do you think for a class without data members, the result is
1?

(for the link you recommended, it does not cover the case why for a class
without data member, its size is 1).


regards,
George

"Alex Blekhman" wrote:

"George" wrote:

Understand that. I have tried another interesting point, I have
tried that
the sizeof of Base is 1 byte in Visual Stduio. I am confused
what is the 1
byte consuming? It has no data members. :-)

The `sizeof' operator never yields 0, even for an empty class.

"sizeof Operator"
http://msdn2.microsoft.com/en-us/library/4s7x1k91.aspx

15.2.3 Replicated Base Classes [hier.replicated]
15.2.4 Virtual Base Classes [hier.vbase]

I have that book at hand. It covers general theories of muliple
inheritance,
ambiguity issue and how to use virtual base class to solve
ambiguity issue.

But seems Bjarne's logics are based on ambiguity issue arises
from different
data members (this is why we need to use virtual base class to
make a single
copy of data member). Again, my classes does not have data
members -- Bjarne
does not covers this situation, and seems my sample beyond his
book. :-)

It doesn't matter whether class contains any members or not.
Language rules don't change magically in presence of class
members. In the book, in order to make the case more apparent
Stroustrup uses class memebrs. He could use a cast to base as
well.

Alex



.



Relevant Pages

  • Re: CreateInstance
    ... It has no data members. ... The `sizeof' operator never yields 0, ... Virtual Base Classes ... ambiguity issue and how to use virtual base class to solve ...
    (microsoft.public.vc.language)
  • Re: CreateInstance
    ... I have read the link and I found as you mentioned sizeof never ... How do you think for a class without data members, ... return 0 for a class type. ...
    (microsoft.public.vc.language)
  • Re: question about fread function
    ... If your data members 'data' and 'nscrdh' are structures the ... sizeof() operator returns the size of the structures with padding. ...
    (comp.lang.c)
  • Re: Passing Type as arugment for C.
    ... The sizeof operator is evaulated by the compiler and most of the ... magic with stdarg to deduce the size of the operands pushed onto the stack. ...
    (comp.programming)
  • Re: Regarding sizeof Operator
    ... "the operand of a sizeof operator is usually not evaluated" ... Although sizeof must evaluate the size of a variable length array under c99 ... "If the type of the operand is a variable length array type, ...
    (comp.lang.c)