Search code examples
c++visual-studiosdlsdl-2

Visual studio error C2027


I am working on my game engine and i get some error which i dont know how to fix. I have Camera which have pointer to GameObject but whenever i use him it said that it is undefined type GameObject. I work at Visual studio 2017 and it give me error C2027.

I already have forward declarating and pointer is assigned to object right in constructor. I look on this page but Thx for any help.

here is 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();

};

Solution

  • The compiler obviously has right :D.

    You had a forwar declaration of GameObject that is fine. What is not fine is here:

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

    How can know the compiler that _ownerObject has a method getWorldLocation?

    You need or to include GameObject definitions or delcare that function inside cpp file and include the right headers.