//Given the following program , what is the output for each of the numbered lines in main()
#include <iostream>
using namespace std;
class X{
public:
X() { cerr << "X()|";}
X (const X&) { cerr << "X(const X&)|";}
~X() { cerr << "~X()|";}
X &operator=(const X&) { cerr << "X::op=|"; return *this;}
};
class B{
public:
B() { cerr << "B()|";}
B (const B&) { cerr << "B(const B&)|";}
virtual ~B() { cerr << "~B()|";}
B &operator=(const B&) { cerr << "B::op=|"; return *this;}
};
class D:public B{
public:
D() { cerr << "D()|";}
D (const D& d):B(d),x_(d.x_) { cerr << "D(const D&)|";}
virtual ~D() { cerr << "~D()|";}
D &operator=(const D& d) {
cerr << "D::op=|";
B::operator=(d);
x_ = d.x_;
return *this;
}
private:
X x_;
};
int main()
{
//B b[2];
//B b1(b[0]);
B *pb = new D;
//B b1(b[0]);
}
When I compile and run the program it prints B()|X()|D()|
I do not understand why it is calling X's constructor.