【发布时间】:2021-01-18 05:01:10
【问题描述】:
我正在开发一个游戏引擎,但出现了这些错误:
严重性代码描述项目文件行删除状态 错误 C2027 使用未定义类型 'AssetManager' SharkEngine F:\Projects\C++\SharkEngine\Text.h 10
和
严重性代码描述项目文件行删除状态 错误 C2011 'AssetManager': 重新定义类型'class' SharkEngine F:\Projects\C++\SharkEngine\AssetManager.h 8
我找不到为什么会出现这些错误。 这是我的代码:
Text.h(C2027 错误的来源)
#pragma once
#include "AssetManager.h"
namespace Text
{
sf::Text NewText(std::string str, std::string font, sf::Color color, int charSize, AssetManager* manager)
{
sf::Text t;
t.setString(str);
t.setFont(*manager->GetFont(font));
t.setCharacterSize(charSize);
t.setFillColor(color);
return t;
}
};
AssetManager.h(C2011 错误的来源)
#pragma once
#include<iostream>
#include<map>
#include<SFML/Graphics.hpp>
#include<SFML/Audio.hpp>
class AssetManager
{
private:
std::map<std::string, sf::Texture*> Textures;
std::map<std::string, sf::Font*> Fonts;
std::map<std::string, sf::SoundBuffer*> AudioClips;
public:
void LoadDir(std::string path, bool absolutePath = false);
#define LoadAllAssets() LoadDir("");
//texture
void LoadTexture(std::string path, std::string name);
sf::Texture* GetTexture(std::string name);
//font
void LoadFont(std::string path, std::string name);
sf::Font* GetFont(std::string name);
//sound buffer
void LoadAudioClips(std::string path, std::string name);
sf::SoundBuffer* GetAudioClips(std::string name);
};
请随时询问任何其他信息。感谢您的宝贵时间!
【问题讨论】:
-
10 和 8 是行号吗?那是
t.setFont(*manager->GetFont(font));和class AssetManager。我猜你没有发布文件的所有内容。错误在哪几行? -
是的,这些是正确的行,问题是程序甚至不想构建,并且在程序启动时加载文件意味着构建。更多这些错误并不代表此类问题。谢谢你的想法。
-
嗨,如果我看起来不礼貌,我很抱歉,所以就像这样一行:Text.h 中的#include "AssetManager.h" 无法正常工作?
-
urks 很抱歉,政客是个糟糕的玩笑,与你无关。删除评论并重新发布
-
我不相信您的错误来自代码中的那些行。例如,在 Text.h 中,您已经在上面三行使用了 AssetManager,如果未声明 AssetManager,则应该已经触发错误。请附上minimal reproducible example 和完整的错误消息
标签: c++ visual-studio compiler-errors