1

given:

class A {
    std::list<int> m_list;
    std::list<int>::iterator m_iterator;
public:
    explicit A() : m_iterator(m_list.begin()) { }
};

Am I guaranteed m_list will be constructed before evaluating ctor initialization list, so that a begin() will correctly dereference its beginning/end? Or should I better use an m_iterator assignment inside ctor body?

user815129
  • 2,236
  • 2
  • 20
  • 40

1 Answers1

5

Members are constructed in declaration order.

So yes m_list will be constructed before m_list.begin() will be called.

Hcorg
  • 11,598
  • 3
  • 31
  • 36