Warning this will be initialized after that

C

Christopher

What causes this kind of warning to occur? why is the compiler forcing
some order of initialization in an initializer list?
I frequently run into this when I am initializing a pointer and an int
in a constructor's initializer list.
 
A

Alf P. Steinbach

* Christopher:
What causes this kind of warning to occur? why is the compiler forcing
some order of initialization in an initializer list?

The language requires that sub-objects (bases and data members) are
initialized in the order they are declared. The order specified in an
initializer list does not matter. A compiler may warn you that you will
not get the order you have used in an initializer list.

To avoid such warnings, use the declaration order in every initializer list.


Cheers, & hth.,

- Alf
 
I

Ian Collins

Christopher said:
What causes this kind of warning to occur? why is the compiler forcing
some order of initialization in an initializer list?
I frequently run into this when I am initializing a pointer and an int
in a constructor's initializer list.

Class members are initialised in the order they are declared, not the
order they appear in initialiser lists.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top