c++constructorinitializationmember-initializationctor-initializer

Is it ok to call a function in the member initializer list?


My gut feeling is it is not. I am in the following situation:

class PluginLoader
{
   public:
      Builder* const p_Builder;
      Logger* const p_Logger;

      //Others
};

PluginLoader::PluginLoader(Builder* const pBuilder)
   :p_Builder(pBuilder), p_Logger(pBuilder->GetLogger())
{
   //Stuff
}

Or should I change the constructor and pass a Logger* const from where PluginLoader is constructed?


Solution

  • That's perfectly fine and normal. p_Builder was initialized before it.