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

using namespace std;

class A {
    int i;
    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;
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.

Follow CodeGalaxy

Mobile Beta

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