// Method One
class ClassName
{
public:
ClassName() : m_vecInts() {}
private:
std::vector<int> m_vecInts;
};
// Method Two
class ClassName
{
public:
ClassName() {} // do nothing
private:
std::vector<int> m_vecInts;
};
What is the correct way to initialize the std::vector data member of the class?
Do we have to initialize it at all?
See http://en.cppreference.com/w/cpp/language/default_initialization
Since
std::vectoris a class type its default constructor is called. So the manual initialization isn’t needed.