Boost logo

Boost :

Subject: Re: [boost] [scope_exit] MSVC error C2355: 'this' : can only be referenced inside non-static member functions
From: Stephan T. Lavavej (stl_at_[hidden])
Date: 2010-08-25 20:04:42

[Lorenzo Caminiti]
> I get this error on MSVC 2008 but the code compiles just fine on GCC:
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86

That's not 2008, it's 2005 (and it's 2005 RTM).

_MSC_VER == 1400, VC8, VS 2005
_MSC_VER == 1500, VC9, VS 2008
_MSC_VER == 1600, VC10, VS 2010

(Our C++ compiler predates *Visual* C++.)

This compiles with VC10 and Boost 1.44.0:

C:\Temp>type meow.cpp
#include <boost/scope_exit.hpp>

struct c {
    void f() {
        typedef void (*this_t)(int this_ );

#if defined(BOOST_MSVC) // for MSVC
        typedef boost::type_of::msvc_typeid_wrapper<
#else // for GCC
        typedef __typeof__(
                        this, (this_t)0
#if defined(BOOST_MSVC) // for MSVC
#else // for GCC

int main() {
    c cc;
    return 0;

C:\Temp>cl /EHsc /nologo /W4 /I . meow.cpp
using native typeof



Stephan T. Lavavej
Visual C++ Libraries Developer

Boost list run by bdawes at, gregod at, cpdaniel at, john at