What will be displayed in the terminal as a result of the following code execution:
#include <iostream>

using namespace std;

const float WEIGHT = 1.0;

class A {
    public:
        A();
        A(int initialCount);

        float mWeight;
        int mCount;
};

A::A(int initialCount) :
        mCount(initialCount),
        mWeight(mCount*WEIGHT)
{
}

int main()
{
    A objA(15);
    cout<<objA.mWeight<<endl;

    return 0;
}
Explanation
When using the list of initializers, members are initialized in the order fixed in the class declaration, and not in the order specified in the list of initializers.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes