2017-08-23 168 views
0

我正在使用我的游戏引擎,并且出现一些我不知道如何解决的错误。 我有相机有指向GameObject的指针,但每当我用他时,它说它是未定义类型的游戏对象。我在Visual Studio 2017工作,它给我错误C2027。Visual studio错误C2027

我已经有前向声明和指针分配给构造函数中的对象权利。我看这页,但 Thx的任何帮助。

这里是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

***它给我错误C2027 ***始终包含错误消息的确切文本。大多数用户将不得不使用谷歌找出什么是C2027。最好从Visual Studio的“输出”选项卡复制错误消息。 – drescherjm

回答

0

不能使用_ownerObject头文件里面。

原因是,你只有转发申报它的类型使用class GameObject;。前向声明只告诉编译器关于现有的类,而不是它看起来的样子(这可以通过包含“GameObject.h”来完成)。因此,编译器无法知道,如果_ownerObject->getWorldLocation()在您的标题行

return _relativeLocation + _ownerObject->getWorldLocation(); 

是一个有效的函数调用。

为了解决这个问题,所有使用_ownerObject的函数都是cpp文件。

0

编译器显然有对:D。

你有一个forwar的声明GameObject这很好。什么是不精是在这里:

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

怎么知道_ownerObject有一个方法getWorldLocation编译器?

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