On 9/21/2010 10:19 AM, James Kanze wrote:
> On Sep 21, 1:06 pm, Victor Bazarov<v.baza...@comcast.invalid> wrote:
>> On 9/21/2010 7:54 AM, dust wrote:
>>> On Sep 21, 4:24 pm, Vladimir Jovic<vladasp...@gmail.com> wrote:
>>>> A::B obj;
>
>>> Isn't this the syntax if the struct is static only??
>
>> It *is* static, sort of. There is only one of 'B' in 'A' (IOW, there is
>> no separate 'B' in every instance of 'A'). If it's easier for you,
>> think of a nested type definition as "an implicitly static member".
>
> Calling it static still confuses the issue, I think. Types
> (classes, enums) always have global binding, and aren't runtime
> objects, so don't have lifetime. Static is overloaded in many
> ways, but they all involve either name binding or object
> lifetime. Since you can't give a class internal binding (one
> meaning of static), and it doesn't have a lifetime (the other
> meaning), the word has no meaning for classes.
It could be that dust has experience in Java, where nested classes can
be declared as static, or not. If they are not, they receive a hidden
pointer to the "this" of the enclosing classes instance. I'm assuming
C++ is different in this regard, and that any struct inside of a class
is a regular struct with a different "name space" (not to be confused
with namespace.)
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
|