05_02.cpp

来自「一些C++的课件和实验源代码」· C++ 代码 · 共 50 行

CPP
50
字号
// 05_02.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

class PlaneHead {
public:
	PlaneHead() { cout << "construct Head." << endl; }
	~PlaneHead(){ cout << "destroy Head." << endl; }
};

class PlaneBody {
public:
	PlaneBody() { cout << "construct Body." << endl; }
	~PlaneBody(){ cout << "destroy Body." << endl; }
};

class PlaneWing { 
	string name;
public:
	PlaneWing(string str) { 
		name = str;
		cout << "construct " << name << " Wing." << endl; }
	~PlaneWing() { cout << "destroy " << name << " Wing." << endl;}
};

class Plane{
	PlaneHead head;
	PlaneBody body;
	PlaneWing lWing, rWing;
public:
	Plane():lWing("Left"), rWing("Right") {
		cout << "construct Plane." << endl;	
	};
	~Plane() { cout << "destroy Plane." << endl; }
};

int main(int argc, char* argv[])
{
	Plane *p = new Plane();
	delete p;

	getch();
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?