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 {
    explicit Clazz(int) {
        cout << 'A';

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

int main() {
    Clazz x(10);
    Clazz y = 10.;
    return 0;
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.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Зареєструйся Зараз
або Підпишись на майбутні тести