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; } –