Compiler Warning (levels 1 and 4) C4355
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Warning (levels 1 and 4) C4355

Error Message

'this' : used in base member initializer list

The this pointer is valid only within nonstatic member functions. It cannot be used in the initializer list for a base class.

The base-class constructors and class member constructors are called before this constructor. In effect, you've passed a pointer to an unconstructed object to another constructor. If those other constructors access any members or call member functions on this, the result will be undefined. You should not use the this pointer until all construction has completed.

This is a level-1 warning under Microsoft extensions (/Ze) and a level-4 warning otherwise.

The following sample generates C4355:

// C4355.cpp
// compile with: /W1 /c
#include <tchar.h>

class CDerived;
class CBase {
   CBase(CDerived *derived): m_pDerived(derived) {};
   virtual void function() = 0;

   CDerived * m_pDerived;

class CDerived : public CBase {
   CDerived() : CBase(this) {};   // C4355 "this" used in derived c'tor
   virtual void function() {};

CBase::~CBase() {
   m_pDerived -> function();

int main() {
   CDerived myDerived;
© 2016 Microsoft