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
Зареєструйся Зараз
або Підпишись на майбутні тести