错误"未在作用域中声明",但带有接口
Error "not declared in the scope" but with interfaces
你看我一直在尝试创建一个std::vector
,其中包含IState
类中的Entity
类。这两个类都是接口。
错误是
在此范围内未声明"实体"
它指向:
protected:
std::vector <Entity*> ent_map;
在IState.h内部
我已经尝试了几个小时来解决它。一旦我在 IState.h 中做了一个前向声明,但一旦我这样做并尝试使用向量,它就会喷出它是一个不完整的类,所以我又回到了原点。
有什么想法吗?
实体.h
#ifdef __ENTITY__
#define __ENTITY__
#include <iostream>
#include <SDL.h>
class Entity
{
public:
virtual ~Entity();
virtual void load(const char* fileName, std::string id, SDL_Renderer* pRenderer) = 0;
virtual void draw() = 0;
virtual void update() = 0 ;
virtual void clean() = 0;
/*void int getX() { return m_x;}
void int getY() { return m_y;}
void std::string getTexID {return textureID;}
*/
};
#endif // __ENTITY__
IState.h
#ifndef IState_
#define IState_
#include "Entity.h"
#include <vector>
class IState
{
public :
virtual ~IState();
virtual void update() = 0;
virtual void render(SDL_Renderer* renderTarget) = 0;
virtual bool onEnter() = 0;
virtual bool onExit() = 0;
virtual void handleEvents(bool* gameLoop,SDL_Event event) = 0;
virtual void resume() = 0;
virtual std::string getStateID() = 0;
virtual void setStateID(std::string id) = 0;
protected:
std::vector <Entity*> ent_map;
};
#endif // IState_
"Entity.h"
的内容根本不包括在内。
改变
#ifdef __ENTITY__
自
#ifndef __ENTITY__
顺便说一句:名称包含双下划线或以下划线开头,后跟大写字母保留在C++中,您需要小心。
相关文章:
- 未在作用域中声明unordered_map
- 有没有一种方法可以在编译时获得作用域类名
- C++quit()函数中可能存在作用域问题
- 未在此作用域OpenCV3.4中声明cvSaveImage
- 全局作用域中函数指针的赋值
- 在类函数中初始化外部作用域变量
- 不同作用域中的静态变量和全局变量
- 是同一作用域的函数部分中的函数调用
- 未在此作用域中声明的函数和变量 (C++)
- 类作用域的类型别名"using":[何时]方法中的用法可以先于类型别名?
- 将作用域枚举转换为基础类型
- 表达式必须具有完整或无作用域的枚举图
- 在构造函数中输入对象时C++类成员作用域
- 无法让"std::enable_if"适用于无作用域枚举
- 为什么不能直接引用作用域枚举类成员,而不能为无作用域枚举生成类成员?
- 函数未在作用域中声明 / 如何结合使用 header.h、header.cpp 和 main.cpp?
- 错误:表达式必须具有算术、无作用域枚举或带有运算符重载的指针类型
- 如何在C++中访问作用域的变量输出?
- 重载时未在 C++ 的作用域错误中声明
- 错误"未在作用域中声明",但带有接口