You are viewing an older revision! See the latest version

Compiler Error 366/

« Compiler-Error-366

Table of Contents

  1. Example

References cannot be uninitialized. Because it is impossible to reinitialize a reference, they must be initialized as soon as they are created. In particular, local and global variables must be initialized where they are defined, and references which are data members of class instances must be initialized in the initializer list of the class's constructor. C++ Reference

Example

In my case, I had defined a reference variable thus:

class X 
{
   int &val;
   int val2;

   X() : val2(3)
   {
   }
}

The error is because I didn't initialize the member 'val' in the constructor.


All wikipages