【问题标题】:'class std::map<std::basic_string<char>, Gui>' has no member named 'emplace''class std::map<std::basic_string<char>, Gui>' 没有名为 'emplace' 的成员
【发布时间】:2015-11-14 16:38:45
【问题描述】:

嗨,Guy 正在寻求帮助,但无法理解问题所在。我正在关注本教程https://www.binpress.com/tutorial/creating-a-city-building-game-with-sfml-part-8-gui-system/130,我使用的是 CodeBlocks 13.12 和 SFML 2.1,但是当我尝试编译代码时,我得到了这个

||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===|
C:\Users\James\Desktop\Summer Repeats 2015\Games Dev 2\Test\src\Game_State_Start.cpp||In constructor 'GameStateStart::GameStateStart(Game*)':|
C:\Users\James\Desktop\Summer Repeats 2015\Games Dev 2\Test\src\Game_State_Start.cpp|100|error: 'class std::map<std::basic_string<char>, Gui>' has no member named 'emplace'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

这是给我这个错误的代码行。

this->guiSystem.emplace("menu", Gui(sf::Vector2f(192, 32), 4, false, game->stylesheets.at("button"),
    { std::make_pair("Load Game", "load_game") }));

我为 C++11 设置了 CodeBlocks 并将 SFML 更改为 SFML-2.3.1-windows-gcc-4.9.2-mingw-32-bit 因为我发现这里说我必须使用 g++ 4.8.0 或更高版本在此页面上std::map emplace gcc 4.8.2,但仍然出现相同的错误,即使我自己尝试遵循它,该网站也给了我要下载的代码,我检查了代码,导入到一个新项目中并且没有工作要么,所以不知道出了什么问题。任何帮助或正确方向的观点将不胜感激。

【问题讨论】:

  • 尝试创建一个非常小的项目。 #include &lt;map&gt; 然后 int main() { std::map&lt;int,int&gt; m; m.emplace(1,1); } 没有别的,看看是否编译。
  • 没用,同样的错误。
  • 我可能发现了错误,SFML 的版本高于 4.8 但我认为 Codeblocks 在查看路由设置后可能只有 4.7.1,可能是错误的,不能完全确定这些东西只是学习.

标签: c++ c++11 gcc sfml


【解决方案1】:

通常我会在评论中发布此内容,但我没有足够的代表。
启动一个新项目并编译并运行这段代码:

#include <iostream>
#include <ostream>

int main()
{
    std::cout << __cplusplus << std::endl;
}

如果打印出来的结果是199711,那么这意味着您没有使用-std=c++11 选项进行编译。如果打印出的结果是201101,则表示您使用的是标准库的过时版本。

【讨论】:

  • 作为 201103 回来了,我认为它是最新的。
【解决方案2】:

找到了解决方案。我最初安装了 codeblocks-13.12mingw-setup,我卸载了这个并安装了 codeblocks-13.12mingw-setup-TDM-GCC-481。现在可以了。感谢大家的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-26
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 2017-03-10
    • 2018-03-11
    相关资源
    最近更新 更多