Which will print the following code:
#include <iostream>

using namespace std;

class A {
    int i;
public:
    A() {
        cout << "in A::A()" << endl;
        i = 0;
    }
    A operator = (A a) {
        cout << "in A::operator=(A)" << endl;
        i = a.i;
    }
};

int main() {
    A a;
    A b = a;
    return 0;
}
Explanation
if A b = a;, the automatically generated copy constructor is called instead of the assignment operator, so the assignment operator cannot output anything because it is never called.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты