R
rona
Hi everyone,
Could someone tell us why the below code compiles and works? Is it
legal in the constructor of class B?
Cheers
Ronny
---------------------------------
#include <iostream>
using namespace std;
class a {
int x;
public:
void show() { cout<<x<<endl; }
a(int xx) : x(xx) {}
a() {}
};
class B {
a ma;
public:
B(int xx);
void disp() { ma.show(); }
};
B::B(int xx) {
ma = a(xx);
}
int main() {
B b(3);
b.disp();
return 0;
}
Could someone tell us why the below code compiles and works? Is it
legal in the constructor of class B?
Cheers
Ronny
---------------------------------
#include <iostream>
using namespace std;
class a {
int x;
public:
void show() { cout<<x<<endl; }
a(int xx) : x(xx) {}
a() {}
};
class B {
a ma;
public:
B(int xx);
void disp() { ma.show(); }
};
B::B(int xx) {
ma = a(xx);
}
int main() {
B b(3);
b.disp();
return 0;
}