提问人:Wungi 提问时间:8/17/2021 最后编辑:Nicol BolasWungi 更新时间:8/17/2021 访问量:264
Visual C++ - 使用模块和概念时无法解析的外部符号
Visual C++ - Unresolved External Symbol when using Modules and Concepts
问:
我正在尝试学习 C++,并一直在使用玩具游戏引擎测试新的模块系统。不幸的是,我不断收到的这个链接错误什么也没告诉我,我不明白我做错了什么。我真正能弄清楚的是,main函数看不到play函数的实现,但我不知道如何解决它。我已经将我的项目削减到最低限度,所以希望经验丰富的 C++ 程序员更清楚。任何意见都值得赞赏,谢谢。
main.cxx
import engine;
int main() {
engine::game<engine::text_ui> my_game("My Game");
my_game.play();
}
引擎.ixx
export module engine;
export import :game;
export import :ui;
游戏.ixx
export module engine:game;
export import <concepts>;
export import <string>;
export import :ui;
namespace engine {
export template<typename ui_t>
requires std::derived_from<ui_t, ui>
class game {
std::string name;
ui_t ui;
public:
game(std::string name) : name{name} {};
void play() const;
};
}
游戏.cxx
module engine:game;
import <concepts>;
import :ui;
namespace engine {
template<typename ui_t>
requires std::derived_from<ui_t, ui>
void game<ui_t>::play() const {
ui.notify(name + " is being played.\n");
}
}
ui.ixx
export module engine:ui;
export import <string>;
export import <iostream>;
namespace engine {
export class ui {
public:
virtual void notify(std::string text) const = 0;
};
export class text_ui : public ui {
std::istream& in{std::cin};
std::ostream& out{std::cout};
public:
void notify(std::string text) const override { out << text; };
};
}
错误
LNK2019 unresolved external symbol
"public: void __thiscall engine::game<class engine::text_ui>::play(void)const "
(?play@?$game@Vtext_ui@engine@@@engine@@QBEXXZ::<!engine>)
referenced in function _main
答: 暂无答案
评论