c++ - Visual C++ - 使用模块和概念时未解析的外部符号
问题描述
我正在尝试学习 C++,并且一直在使用玩具游戏引擎测试新的模块系统。不幸的是,我不断收到的这个链接错误什么也没告诉我,我也不明白我做错了什么。我真正能弄清楚的是,主函数看不到播放功能的实现,但我不知道如何修复它。我已将我的项目缩减到最低限度,因此希望对有经验的 C++ 程序员来说更清楚。任何输入表示赞赏,谢谢。
主文件
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
解决方案
推荐阅读
- javascript - JavaScript 括号解释
- c# - 如何在 c# 模型中的 typescript 中转换 propName: string: any?
- ruby - 在 Windows 上安装 ruby 版本 2.1.2 没有成功
- ruby-on-rails - 在Rails中提交表单之前,有没有办法覆盖选择中禁用选项的id
- java - Double.parseDouble 丢失小数位
- javascript - jQuery 表单验证在 JSP 中不起作用
- c++ - CLion 在远程计算机上找不到 C/C++ 标准库
- react-native - 如何在 React Native WebView 中加载视图之前在 WebView 本地存储中设置值
- dart - 如何从推送通知重定向到颤动的页面
- python - 为什么这段代码不输出获胜者变量?