Should I use a Constructor or init function in C++

Viewed 6680

There is a class B has Class A member m_a

class A{
    A(...);
    ~A();
    init(...);
    ...//other methods;
    ...//data
    }

in order to initialize m_a with certain value, I could use the constructor or the init() function. If I use constructor, and the value can't be decide in the class B constructor, I would have to use a A* m_a and new A(...) to initialize later. Or if I use init() function, I could just use A a as the member of the B class. So in this case is init() function is a better way of doing it?

3 Answers
Related