Hey, can someone explain the cause of this warning:
1 2 3 4
../algorithms/SingleQueueAlgorithm.h: In constructor 'QueueSetIterator::QueueSetIterator()':
../algorithms/SingleQueueAlgorithm.h:30:12: warning: 'QueueSetIterator::q' will be initialized after
../algorithms/SingleQueueAlgorithm.h:29:8: warning: 'Node* QueueSetIterator::item'
../algorithms/SingleQueueAlgorithm.cpp:25:1: warning: when initialized here
with this code (constructors of class QueueSetIterator) :
A::A()
//note the order
:member_2(),
member_1()
{}
Even though in the initialization list I put member_2 before member_1, the compiler will initialize member_1 first because it appears first in the class definition. Initialization follows the order of declaration, not the order of the initialization list. You have to be careful with that or it could lead to subtle bugs.