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
Обратная Связь
Зарегистрируйся сейчас
или Подпишись на будущие тесты