stewart.tootill@softel.co.uk schreef:[color=blue]
> Hello,
>
> I have a template class, which holds a fixed size array of elements[/color]
in[color=blue]
> it. It can't be a vector because the elements aren't copy[/color]
constructable[color=blue]
> and the whole thing is an optimisation to avoid heap allocation[/color]
anyway,[color=blue]
> so vector doesn't fit the bill.
>
> Anyway, the elements inside it are in a suitably aligned chunk of
> memory, which I am constructing using placement new. So far so good.
>
> Unfortunately the typename is quite long winded, so I have a typedef[/color]
to[color=blue]
> it. For the sake of argument, we'll call it my_nested_type.
>
> my_obj::~my_obj()
> {
> for ( size_t pos = 0; pos < noofElements; ++pos )
> my_array[pos].~my_nested_type();
> }
>
> and I was surprised when it compiled. I know this is valid syntax for
> calling a destructor of a class, but because it is a typedef I really
> didn't expect it to compile.[/color]
It's legal. There are a number of variantions that are allowed, and
naming a dtor is one area in which older compilers might fail. Don't
woory too much, though, this particular variant is one of the easier
variations.
Regards,
Michiel Salters