Hi, here is a tea question:
the warning in subject is "class::constname will be initialized after const type class::secondconstname when initialized here [the initialization row]"
Situation:
let's suppose that we declare two constant variables in a class
class myCuriousClass{
private:
const int constant1;
const int constant2;
public:
myCuriousClass();
};
class myCuriousClass{
private:
const int constant1;
const int constant2;
public:
myCuriousClass();
};
To copy to clipboard, switch view to plain text mode
and then we valorize them as expected within a class: by the constructor
myCuriousClass::myCuriousClass()
:constant2(2),constant1(1)
{
//nothing smart to do here
}
myCuriousClass::myCuriousClass()
:constant2(2),constant1(1)
{
//nothing smart to do here
}
To copy to clipboard, switch view to plain text mode
the fact that we initialized them in reversed order than we declared them makes the compiler complain
myCuriousClass::constant1 will be initialized before const int myCuriousClass::constant2 when initialized here
(row 3 of the second piece of code)
So the question is, what is the problem if I reverse the order? Why was dedicated a warning to this situation?
PS: for this test I used a MinGW compiler.
Thank you for your attention
Bookmarks