结构的共享指针可在所有文件中使用处理程序实例

我正在尝试制作游戏,但在尝试在其他“处理程序”(InputManager,Logger,AssetsManager等)中使用其他类的相同实例时遇到一些困难。这些是错误:

  
      
  • AssetManager.h(14,35):错误C2061:语法错误:标识符'LogDataRef'
  •   
  • AssetManager.h(30,21):错误C3646:“ logdata”:未知的替代说明符
  •   
  • AssetManager.h(30,21):错误C4430:缺少类型说明符-假定为int。注意:C ++不支持default-int
  •   

这是我的主要游戏标头,其中我实例化了所有不同的处理程序类

#pragma once
#include <iostream>

#include "SFML/Graphics.hpp"
#include "DEFINITIONS.h"

#include "AssetManager.h"
#include "StateMachine.h"
#include "LogSystem.h"
#include "FileParser.h"



namespace ME2D
{

    struct GameData {
        StateMachine machine;
        sf::RenderWindow window;
    };

    struct AssetData {
        AssetManager assetmanager;
    };

    struct LogData {
        LogSystem logger;
    };

    struct ParseData {
        FileParser parser;
    };

    typedef std::shared_ptr<GameData> GameDataRef;
    typedef std::shared_ptr<AssetData> AssetDataRef;
    typedef std::shared_ptr<LogData> LogDataRef;
    typedef std::shared_ptr<ParseData> ParseDataRef;

    class TDGame
    {
    public:
        TDGame();
    private:
        void Run();
    private:
        GameDataRef data = std::make_shared<GameData>();
        AssetDataRef assetdata = std::make_shared<AssetData>();
        LogDataRef logdata = std::make_shared<LogData>();
        ParseDataRef parsedata = std::make_shared<ParseData>();

        sf::Clock clock;

        const float dt = 1 / 60.f;
    };
}

这是AssetManager类的头文件。只是在公共场合删除了这些功能以节省空间(只是基本的装载程序和吸气剂)。

#pragma once
#include <iostream>
#include <map>
#include "SFML/Graphics.hpp"
#include "SFML/Audio.hpp"
#include "Block.h"
#include "2DGame.h"

namespace ME2D
{
    class AssetManager
    {
    public:
        // some functions here
    private:
        LogDataRef logdata;

        std::map<std::string,sf::Texture> mTextures;
        std::map<std::string,sf::Sprite> mSprites;
        std::map<std::string,sf::SoundBuffer> mSBuffers;
        std::map<std::string,sf::Sound> mSounds;
        std::map<std::string,ME2D::Block> mBlocks;
    };
}

我需要在其他处理程序中使用主游戏标题中的实例。对于此示例,我需要使用AssetsManager类内游戏标头中的实例化日志类(当然,我也需要在其他处理程序中使用它,因此它将所有记录的信息写入一个文件中,而不是创建每个处理程序中都有多个记录器实例,并制作了多个日志文件。

还应注意的是,我对shared_ptr或make_shared的工作方式或它们的确切用途一无所知,看着一个家伙从youtube视频中制作了状态机(因为我也不知道该如何做,堆栈和那些东西都在制作状态机的方式中存在,我可能在某种程度上可以理解),并且也非常感谢您提供有关这些信息。基本上我是一个初学者,最多从事3个月的编码工作,他正在尝试制作自己的第一个游戏并在此过程中学习。

k702059455 回答:结构的共享指针可在所有文件中使用处理程序实例

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3141602.html

大家都在问