Re: Bug in C++ /CLI 2005
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Thu, 9 Oct 2008 16:01:21 -0500
Mark Salsbery [MVP] wrote:
"Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx> wrote in message
news:ex5QaOhKJHA.1160@xxxxxxxxxxxxxxxxxxxxxxx
Mark Salsbery [MVP] wrote:
"Howard Swope" <howard_swopeAThms3DOTcom> wrote in message
news:Oyv$tJgJJHA.1308@xxxxxxxxxxxxxxxxxxxxxxx
Declaring variables with stack semantics is one of the Advertised
features in C++ CLI
Not member variables.
It makes no sense to have member variables with stack semantics -
there's no "stack" involved unless you have an actual object.
I definitely do NOT agree with this. Stack semantics give you all
the correct calls to Dispose in all the corner cases, like
exceptions thrown in constructor initializer lists, automatically. Stack
semantics is perhaps not the best description -- scoped
variable lifetime (vs dynamic lifetime) might be better.
Hi Ben,
How does scoped variable lifetime apply to member variables?
The scoped variable lifetime of a member variable is determined by
it's containing class, right?
For this to work, the compiler would need to generate the gcnew calls
for the member variables. That means one would be stuck with a
parameterless constructor, unless some (possibly obscure) construct
syntax was added to the language to allow other constructor calls for
these "automatic" variables.
Whoa, is someone impersonating the real Mark, the C++ MVP? Or are you just
having an off day?
Because ctor initializer-lists are hardly obscure and fully standard. I
even mentioned them in my post.
The same thing effectively happens for members of native types which take
parameters to their constructors, except it's use of placement new vs gcnew,
and the managed type isn't actually inside the containing class (although
they will be placed contiguously in memory under the most obvious
implementation of the managed heap, which is a stack not a heap anyway).
I imagine a similar argument occurred when this feature of the
language was designed. :)
Is it a bug or by design?
I still think, given the way it currently works, that stack semantics
on ref class member variables shouldn't be allowed.
Mark
.
- Follow-Ups:
- Re: Bug in C++ /CLI 2005
- From: Mark Salsbery [MVP]
- Re: Bug in C++ /CLI 2005
- References:
- Bug in C++ /CLI 2005
- From: Howard Swope
- Re: Bug in C++ /CLI 2005
- From: Mark Salsbery [MVP]
- Re: Bug in C++ /CLI 2005
- From: Ben Voigt [C++ MVP]
- Re: Bug in C++ /CLI 2005
- From: Mark Salsbery [MVP]
- Bug in C++ /CLI 2005
- Prev by Date: Re: Bug in C++ /CLI 2005
- Next by Date: Re: Bug in C++ /CLI 2005
- Previous by thread: Re: Bug in C++ /CLI 2005
- Next by thread: Re: Bug in C++ /CLI 2005
- Index(es):
Relevant Pages
|