Hi all,

With the MS C++ compiler and our current warning settings, the following code example produces the warning:

test.cxx(18) : warning C4355: 'this' : used in base member initializer list

class A
{
public:
    A() {}
};

class B
{
    A& _a;
public:
    B( A& a ) : _a(a) {}
};

class C : public A
{
    B _b;
public:
    C() : _b( *(A*)this ) {}
};

int main()
{
    C c;
}

Using 'this' in the ctor initializer list can be dangerous, if you don't know what you do. The above example uses a safe way to provide this.
I think we have two possible ways to solve this problem.
- Turn of the warning for every occurrence in the code.
- Switch of C4355 for Windows globally.

I would propose to disable the warning C4355 for Windows, because we have many places where we use 'this' in the initializer list (for example, every dialog ctor).

More info about C4355:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/C4355.asp

Regards,
Carsten

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to