// 我给你写了一个DemoProgram,希望你能看懂。
// 也希望这个程序正是你所要的。
#include <iostream>
#include <cstdlib>
using namespace std;
class A
{
private:
int a;
public:
A()
{
a = 0;
}
A(const int n)
{
a = n;
}
const void display() const //const member function
{
cout<<a<<endl;
}
};
class B
{
private:
const A a; // const object as member
const int b; // const variable as member
public:
//constructor using initialing list
B(const A & anotherA, const int n) : a(anotherA), b(n)
{
}
//copy contructor using initialing list
B(const B & anotherB): a(anotherB.a), b(anotherB.b)
{
}
const void display() const // const member function
{
a.display();
cout<<endl<<b<<endl;
}
};
int main(int args, char * arg[])
{
// here is the code for testing
A a(3);
B b1(a, 6);
B b2(b1);
b2.display();
system("pause");
return 0;
}