<span style="font-size:18px;">// HelloWorld.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class demo
{
public:
demo(){cout<<"无参构造函数"<<endl;};
demo(int i){x=i;cout<<"有参构造函数"<<endl;}
int get(){return x;}
~demo(){cout<<"函数析构完毕"<<endl;}
private:
int x;
};
class Human
{
public:
Human(int i,int j,int k,int m):height(i),wid(j),d1(k),d2(m){cout<<"机器人制造完毕!\n性能为:"<<height*wid<<endl;cout<<"能耗为:"<<d1.get()*d2.get()<<endl; }
private:
int height;
int wid;
demo d1;//上面d1,d2的构造顺序是按照这里成员变量的声明顺序,析构顺序与声明顺序相反。
demo d2;
};
int _tmain(int argc, _TCHAR* argv[])
{
Human h(1,2,3,4);
system("pause");
return 0;
}</span>