0
!我工作的一炮模板,它應該是這樣的:使用類作爲模板類型
template <Bullet>
class gun
{
};
那子彈是一個類,將在其他文件中定義,我的問題是如何在槍使用子彈作爲一種類型?我怎樣才能將一個類用作其他類的模板?我想要一點點長解釋! 謝謝...!
這就是我試圖做的:
#include "Bullet.h"
#include <iostream>
using namespace std;
#define BulletWeapon1 100
#define BulletWeapon2 30
#define BulletWeapon3 50
enum Weapons
{
Gun1,Gun2,Gun3
}CurrentWeapon;
template <class T=Bullet>
class Gun
{
};
int main()
{
return 0;
}
謝謝...! 我在我的課堂上定義了一個來自T的X,但是我可以'使用任何Bullet方法! 我定義我的模板類是這樣的: Gun g; 那現在有什麼問題?! –
@PeymanTahghighi「我在課堂上定義了一個來自T的X,但我不能使用任何Bullet方法!」 - 我很努力去理解。你可以發佈非工作代碼[here](http://coliru.stacked-crooked.com/)並點擊「Share!」並通過鏈接給我? – Shoe
#包括「Bullet1。h」的使用命名空間std 的#include ; 的#define BulletWeapon1 100 的#define BulletWeapon2 30 的#define BulletWeapon3 50個 枚舉武器 { \t Gun1,Gun2,Gun3 } CurrentWeapon; 模板 類槍 { }; INT主() { \t槍克; \t返回0; } –