'calling methods of a member variable as part of parent class "initalization" in constructor body

The right way to initialize member variables (m_unit in this example) is through the ctors initializer list. But lets say the parent class (Server in the example) also needs to call a couple other functions of that member variable (see below) as part of the initialization. These functions wouldn't make sense inside the ctor of Unit in general but in the specific context of Server it makes sense that they are part of the initialization.

I have been trying to keep the ctor body as minimal as possible. And initializing almost everything in the initializer list, except for stuff that needs resolution between 2 or more member variables.

However in this case, is the ctor body the recommended/only way for calling these methods?

class Unit
{
public:
    Unit(const std::string & description)
    : m_description {description}
    { }

    void method1() { std::cout << "method1" << std::endl; }
    void method2() { std::cout << "method2" << std::endl; } 
private:
    std::string m_description;
};


class Server 
{
public:
    Server(const std::string & description )
    : m_unit {description}
    { 
        m_unit.method1();
        m_unit.method2();
    }

private:
    Unit m_unit; 
};

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source