所以,我收到以下错误:命名空间的问题
..\Actor.h:35: error: `Attack' is not a member of `RadiantFlux'
..\Actor.h:35: error: template argument 1 is invalid
..\Actor.h:35: error: template argument 2 is invalid
..\Actor.h:35: error: ISO C++ forbids declaration of `attacks' with no type
在这条线(其中包括):
std::vector<RadiantFlux::Attack> attacks;
以下是相关文件:
Actor.h:
#ifndef ACTOR_H_
#define ACTOR_H_
#include <string>
#include <vector>
#include "Attack.h"
namespace RadiantFlux {
...
class Actor {
private:
std::string name;
int health;
std::vector<RadiantFlux::Attack> attacks;
Attributes attributes;
public:
...
};
}
#endif /* ACTOR_H_ */
Attack.h:
#ifndef ATTACK_H_
#define ATTACK_H_
#include <string>
#include <stdlib.h>
#include <time.h>
#include "Actor.h"
namespace RadiantFlux {
...
class Attack {
private:
...
public:
...
};
}
#endif /* ATTACK_H_ */
为什么我会收到这些错误,我该如何解决这些错误?我假设它是与命名空间...
如果我这样做,我得到一个错误:” .. \ Actor.h:26:错误:向前声明'结构RadiantFlux ::攻击'” – cactusbin
我不认为一个模板参数可以作为前向声明吗?我认为Actor应该在Attack中声明为forward。但是,真的,我认为可能有不同的设计方式,以便依赖性是线性的而不是循环的。 – Kevin
@cactusbin:你需要为'Attack'转发声明'Actor',而不是反过来(为什么你需要这种依赖呢?)。 –