尝试使用我的“层”类,将 3 个对象“drawObject”放入其 vector 中,并出现超出范围错误。
我到处都看到他们只是做“vector >Class< vectorName”;并且有效!
图层类:
#include <vector>
#include "DrawObject.h"
using namespace std;
class layer
{
public:
layer();
virtual ~layer();
private:
vector<DrawObject> objects; <--------------- Error here! "'DrawObject' was not declared in this scope"
};
绘图对象类:
#include <SDL/SDL.h>
#include "AnimationSet.h"
class drawObject
{
public:
drawObject(char* name, char* surfaceFile, int xPos, int yPos, int drawLevel, bool willMoveVar, int animationNumber);
drawObject(char* name, char* surfaceFile, int xPos, int yPos, int drawLevel, bool willMoveVar);
virtual ~drawObject();
SDL_Surface* loadImage(char* surfaceFile);
SDL_Surface* getSurface();
void setSurface(SDL_Surface* surface);
char* getName();
void setName(char* name);
int getID();
void setID(int ID);
float getX();
void addX(float xAdd);
void setX(float xSet);
float getY();
void addY(float yAdd);
void setY(float ySet);
bool isSprite();
void setIsSprite(bool isSprite);
bool willMove();
void setWillMove(bool willMove);
bool draw();
void setDraw(bool draw);
private:
SDL_Surface* surface = NULL; // Imagem, no caso de único sprite; caso contrário, spritesheet.
char* name;
int ID;
float xPos;
float yPos;
bool isSpriteVar; // Se isSprite, imagem é spritesheet.
bool willMoveVar;
bool drawVar;
};
最佳答案
vector<DrawObject>
应该是 vector<drawObject>
, 不? C++区分大小写,你定义了类drawObject
但尝试使用 DrawObject
.
关于c++ - 'DrawObject' 未在此范围内声明错误,使用 std::vector,尝试存储类对象 (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14174215/