Visual Studio错误C2027

时间:2017-08-23 15:23:27

标签: c++ visual-studio sdl sdl-2

我正在研究我的游戏引擎,我得到一些错误,我不知道如何修复。 我有摄像头,它有指向GameObject的指针,但每当我使用他时,它说它是未定义的类型GameObject。我在Visual Studio 2017工作,它给了我错误C2027。

我已经有前向声明,并且指针在构造函数中被赋值给对象。我看这个页面但是 感谢任何帮助。

这是camera.h

#pragma once

#include <SDL.h>

#include <SDL_image.h>
#include <map>
#include <algorithm>

class GameObject;

#include "Camera_manager.h"
#include "gameObject.h"
#include "Interface_SDL.h"
#include "Layer_manager.h"

#include "Vector2f.h"
#include "Typedef.h"



class Camera : public Interface_SDL
{
public:
    Camera(float relativeX, float relativeY, GameObject* ownerObject, ScreenDestination screenDestination, float cameraResolutionWidth, float cameraResolutionHeight, Layer_manager* layerManager);
    ~Camera();

    //Pozice kamery
    Vector2f _relativeLocation;
    //Object kde je umístěna    
    GameObject* _ownerObject;

    bool active;


    float _cameraResolutionWidth;
    float _cameraResolutionHeight;

    inline float getCameraResolutionWidth() { return _cameraResolutionWidth; }
    inline float getCameraResolutionHeight() { return _cameraResolutionHeight; }



    //Getter pro rozměry kamery v rozmezí 0 - 1
    float getCameraWidthInPercent() { return _screenDestination.XEnd - _screenDestination.XStart; }
    float getCameraHeightInPercent() { return _screenDestination.YEnd - _screenDestination.YStart; }
    //Vrací pozici na obrazovce
    inline float getScreenXstart() {return _screenDestination.XStart * Interface_SDL::_windowWidth; }
    inline float getScreenYstart() { return _screenDestination.YStart * Interface_SDL::_windowHeight; }

    ScreenDestination _screenDestination;
    Layer_manager* _layerManager;
    //getter of LayerManager
    Layer_manager* getLayerManger() { return _layerManager;}

    inline Vector2f getWorldPos() { return _relativeLocation + _ownerObject->getWorldLocation(); }
    inline float getWorldPosX() { return _relativeLocation.GetX() + _ownerObject->getWorldLocation().GetX(); }
    inline float getWorldPosY() { return _relativeLocation.GetY() + _ownerObject->getWorldLocation().GetY(); }



    SDL_Texture* getTexture(int layerNumber);

    //Věco pro mazání textur
    SDL_Texture* cleaningTexture;
    SDL_Rect* cleaningRect;


    //LAYERY
    SDL_Texture* textureLayer0;
    SDL_Texture* textureLayer1;
    SDL_Texture* textureLayer2;
    SDL_Texture* textureLayer3;
    SDL_Texture* textureLayer4;
    SDL_Texture* textureLayer5;
    SDL_Texture* textureLayer6;
    SDL_Texture* textureLayer7;
    SDL_Texture* textureLayer8;
    SDL_Texture* textureLayer9;


    //Funkce pro správu textur

    //Vyčistí všechny Layery a nastaví je na NO USED
    void clearAllLayers();

    //Vyčistí texturu která se vloží
    void clearTexture(SDL_Texture* texture);

    //resize layers
    void resizeLayers(int width, int height);





    void handleEvents();
    void update();

};

2 个答案:

答案 0 :(得分:0)

您无法在头文件中使用_ownerObject

原因是您只使用class GameObject; 转发声明其类型。前向声明只告诉编译器有关类的存在,而不是它的外观(通过包含“GameObject.h”来完成)。因此,编译器无法知道标题行中是否_ownerObject->getWorldLocation()

return _relativeLocation + _ownerObject->getWorldLocation();

是一个有效的函数调用。

要解决此问题,请使用_ownerObject将所有函数移动到cpp文件。

答案 1 :(得分:0)

编译器显然有权:D。

你有GameObject的转发声明,没问题。什么不好在这里:

inline Vector2f getWorldPos() { return _relativeLocation + _ownerObject->getWorldLocation(); }

如何知道_ownerObjectgetWorldLocation方法的编译器?

您需要或在cpp文件中包含GameObject定义或delcare,并包含正确的标题。