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: 2010-08-26 11:52:02
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.
However, the 'most preferred/natural syntax' relied on the somewhat rude
definition of a function-style macro named 'this' (to support detection
of the presence of 'this' as the first element of a preprocessor
sequence) which, whilst innocuous, violates 126.96.36.199.1:
'Nor shall such a translation unit define macros for names lexically
identical to keywords.'
This may not be an issue for localfunction if you are always capturing
'this' or have a distinct interface for it's use in member functions.
I have attached my latest version of the patch which still applies fine
to 1.44 and, I think, works on cl versions from vc7.1 upwards.
You should be able to use the same type index trick in localfunction.
The key definition is the function-style macro
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk