c++ - 'DrawObject' 未在此范围内声明错误,使用 std::vector,尝试存储类对象 (c++)

标签 c++ object scope instance

尝试使用我的“层”类,将 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/

相关文章:

c++ - 如何解决分配和释放不匹配的错误?

c++ - 以下哪项关于对象的陈述是正确的?

c++ - OpenCV 从 VS2013 迁移到 QT 5.5

c++ - 多线程时QFileDialog绘画问题

c++ - HashMap 元素的值未正确打印

javascript - 检查对象是否具有javascript中的一组属性

objective-c - Objective-C 中的类属性列表

javascript - AngularJS - 范围未应用于 Controller 功能内的 View

c++ - 附加到 vector 时出现 "does not name a type"错误

java - numberOfPatrons 的范围是什么?为什么?