Subject: Re: [boost] [scope_exit] MSVC error C2355: 'this' : can only be referenced inside non-static member functions
From: Adam Butcher (dev.lists_at_[hidden])
Date: 2011-03-01 12:06:55
On Tue, March 1, 2011 4:38 pm, lcaminiti wrote:
>>>On Thu, August 26, 2010 12:49 am, Lorenzo Caminiti wrote:
>>> I am trying to use Boost.ScopeExit parameter binding mechanism to
>>> implement Boost.LocalFunction. To do so, I need to use some internal
>>> ScopeExit code to detect the type of `this` and bind its value to the
>>> local function declaration.
>>> 2) Do you know of a workaround for this problem?
>>I posted a workaround for this a while back
>>(http://lists.boost.org/Archives/boost/2009/03/149540.php) which used
>>type indexing (where the index for typeof(this) is captured outside of a
>>template parameter list) to avoid specifying 'this' in a template
>>parameter list. The mechanics for the solution came from boost.typeof.
>>You should be able to use the same type index trick in localfunction.
>>The key definition is the function-style macro
> Why is this patch defining the following accessors for the ScopeExit
> I think these are meant to use `this` to access the bound object instead
> of the local struct object. However, these accessors don't work because
> `this->` (and `*this`) never calls the overloaded `operator->`:
> Am I not understanding the purpose of the patch's assessors correctly?
At the time the suggest syntax for accessing the enclosing class'
this-pointer was the expression
So from within the scope-exit you would use (*this) as the object of the
enclosing class (rather than plain 'this' which refers to the instance
of the scope-exit class). Though contentious, this was my best effort
at the time to get the word 'this' into member accesses. Other
suggestions IIRC where calling explicit functions such as
enclosing_this()-> or this_()-> or having those names as pointer members
(i.e. enclosing_this->, or this_->).
The reason for the implicit conversion to reference-to the enclosing
instance was to allow passing of (*this) to functions that expected a
pointer or reference to the enclosing class.
Hope this helps.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk