?? singelhorse_1.cpp
字號:
// SingelHorse_1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
//武器類
class Weapon
{
public:
virtual void Assault() = 0; //純虛函數
};
//長槍類
class Lance : public Weapon
{
public:
virtual void Assault()
{
cout << " I kill enemy with the Lance and can kill 10 every time!" << endl;
}
};
//寶劍類
class Sword : public Weapon
{
public:
virtual void Assault()
{
cout << " I kill enemy with the sword and can kill 20 every time!" << endl;
}
};
//武將類
class General
{
private:
string m_strName;
Weapon *m_pWeapon;
public:
General(string strName):m_strName(strName),m_pWeapon(new Lance())
{
}
~General()
{
if ( m_pWeapon != NULL ) delete m_pWeapon;
}
void SetWeapon(Weapon *pWeapon)
{
if ( m_pWeapon != NULL ) delete m_pWeapon;
m_pWeapon = pWeapon;
}
void performAssault()
{
m_pWeapon->Assault();
}
void Advance()
{
cout << "Go,Go,Go!!!" << endl;
}
};
int main(int argc, char* argv[])
{
//生成趙云對象
General zy("Zhao Yun");
//前進
zy.Advance();
//攻擊
zy.performAssault();
//更換武器
zy.SetWeapon(new Sword());
zy.Advance();
zy.performAssault();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -