-4

I met this method declaration syntax in some C++ code :

formatted_log_t( log_level_t level, const wchar_t* msg ) : fmt(msg), level(level) {}

I don't understand how this is processed, the presence of ":", "fmt" & "level" before curly braces...

ZheFrench
  • 1,121
  • 2
  • 21
  • 43

1 Answers1

2

It's the C++ Initialization list. You can use it with class constructor example

class MaClasse
{
    int myInt;
    MaClasse(int value) : myInt(value) 
    {
    }
};

It is used to initialize member variable. It is faster to use the initialization list than use initialization in the body of the constructor

Pumkko
  • 1,473
  • 14
  • 19