Having the constructors, one of which with explicit specifier, what will be the reuslt of folllowing code execution?
#include <iostream>

using namespace std;

class Clazz {
public:
    explicit Clazz(int) {
        cout << 'A';
    }

    Clazz(char) {
        cout << 'B';
    }
};

int main() {
    Clazz x(10);
    Clazz y = 10.;
    return 0;
}
Explanation
When creating x, an explicit notation is used, therefore both constructors are considered, and since numeric constants are by default of the type int, the first constructor is invoked. For y, only the second constructor is considered, since, for the first one, the implicit form cannot be used.

Follow CodeGalaxy

Mobile Beta

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