Explain each line in main (you can put it in the comments) and explain why the output looks how it looks.
Explain each line in main (you can put it in the comments) and explain why the output looks how it looks.
#include <iostream>
using namespace std;
class A
{
public:
A()
{
n=0;
}
A(int x)
{
n=x;
}
void f()
{
n++;
}
void g()
{
f();
n=n*2;
f();
}
int k()
{
return n;
}
void p()
{
cout<<n<<endl;
}
private:
int n;
};
void main()
{
A a;
A b(2);
A c=b;
A d=A(3);
a.f();
b.g();
c.f();
d.g();
d.p();
A e(a.k() + b.k() + c.k() + d.k());
e.p();
}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









