搞不懂怎么是这样
我是新手,今天在6.0上运行下面代码,结果我怎么都想不通,求大家帮帮忙。
#include <iostream>
using namespace std;
class Matter
{
public:
Matter(int id) : a(id)
{ cout<<" Matter for "<<a<<"\n";
}
~Matter()
{
cout<<" Matter in "<<a<<"\n";
}
private:
const int a;
};
class World
{
public:
World(int id) : a(id),ma(a)
{ cout<<"hello from world "<<a<<".\n";
}
~World()
{
cout<<"goodbye from world "<<a<<".\n";
}
private:
const int a;
const Matter ma;
};
World Theuniverse(1);
void main()
{
World Smalleworld(2);
}
结果是:
Matter for 1
hello from world 1.
Matter for 2
hello from world 2.
goodbye from world 2.
Matter in 2