Is it ok to call a function in constructor initializer list?

nakiya picture nakiya · Nov 12, 2010 · Viewed 35.4k times · Source

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?

Answer

GManNickG picture GManNickG · Nov 12, 2010

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