warning 'will be initialized after'

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) :
1
2
QueueSetIterator::QueueSetIterator() : q(NULL), item(NULL) { }
QueueSetIterator::QueueSetIterator(QueueSet* q_) : q(q_){ item = q->extract(0); }

where q and item are pointers

thanks for any consideration
-Atari
Let's say you have a class like this:
1
2
3
4
5
6
class A{
public:
    T member_1;
    T member_2;
    A();
};
And this is the definition of A::A():
1
2
3
4
5
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.
Topic archived. No new replies allowed.