构造函数c ++的问题

Cha*_*had 4 c++

所以我为这些Weapon类的构造函数提供了这个代码:

Weapon(const WeaponsDB * wepDB);
Weapon(const WeaponsDB * wepDB_, int * weaponlist);
~Weapon(void);  
Run Code Online (Sandbox Code Playgroud)

而且我一直收到错误:

1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(20) : error C2062: type 'int' unexpected
Run Code Online (Sandbox Code Playgroud)

和随之而来的错误(超过列出的):

1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(21) : error C2059: syntax error : '('
1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(21) : error C2238: unexpected token(s) preceding ';'
1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(33) : error C2327: '<unnamed-tag>::maxWeapons' : is not a type name, static, or enumerator
1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(33) : error C2065: 'maxWeapons' : undeclared identifier
1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(38) : warning C4094: untagged 'class' declared no symbols
Run Code Online (Sandbox Code Playgroud)

我是一个半新手,我无法弄明白.

第21行是第二个构造函数,第一个构造函数不会导致错误.另外,如果我注释掉这个构造函数,我仍然会在构造函数之后列出所有错误.知道问题可能是什么?

以下是上面的代码供参考:

#ifndef Weapon
#define Weapon
#include <allegro.h>
#include <stdio.h>
#include <iostream>

using namespace std;

class WeaponsDB;
class MenuDriver;
class Ammo;

class Weapon
{
public:
.....
Run Code Online (Sandbox Code Playgroud)

Ana*_*tts 19

#ifndef Weapon
#define Weapon
Run Code Online (Sandbox Code Playgroud)

这几乎肯定会导致奇怪; 调用常量WEAPON_H代替.


Tim*_*Tim 7

所以你将你的类命名为预处理器指令?这是我会避免的.

尝试更改预处理器武器或制作不同的类名.我认为它会更好.


Mar*_*som 5

我认为问题在于#define Weapon - 代码中稍后出现的"武器"将被删除或替换为你不想要的东西.