【问题标题】:why does boost::assign::ptr_map_insert changes constructor argument calls to const references?为什么 boost::assign::ptr_map_insert 将构造函数参数调用更改为 const 引用?
【发布时间】:2012-07-11 17:26:07
【问题描述】:

我对以下行为感到困惑:

我的“Application”类使用 ptr_map_insert 将“SplashScreen”类型的构造函数元素(派生自我的作为容器类型的“Screen”类)添加到 Screen 类型的指针容器中。示例:

boost::assign::ptr_map_insert<SplashScreen>(screenContainer_)(GameScreens::Splash, curWindow_, curFileSystem_, curInputManager_);

根据ptr_map_insert的文档,最后一对括号以key开头,后面的参数传递给SplashScreen类的构造函数。

curWindow_ 等是我的类“应用程序”的非常量私有成员

不知道为什么,GCC报错是因为传给构造函数的参数是const引用,而SplashScreen的构造函数需要正则引用。

SplashScreen(sf::RenderWindow& curWindow, System::FileSystem& curFileSystem, System::InputManager& curInputManager);

完整的错误消息如下,部分由我翻译,因为它是/曾经是德语。

/usr/include/boost/preprocessor/iteration/detail/local.hpp: In Elementfunktion »boost::assign::ptr_map_inserter<PtrMap, Obj>& boost::assign::ptr_map_inserter<PtrMap, Obj>::operator()(const T&, const T0&, const T1&, const T2&) [with T = Oxid::GameScreens::gameScreenEnum, T0 = sf::RenderWindow, T1 = Oxid::System::FileSystem, T2 = Oxid::System::InputManager, PtrMap = boost::ptr_map<Oxid::GameScreens::gameScreenEnum, Oxid::Screen>, Obj = Oxid::Game::SplashScreen, boost::assign::ptr_map_inserter<PtrMap, Obj> = boost::assign::ptr_map_inserter<boost::ptr_map<Oxid::GameScreens::gameScreenEnum, Oxid::Screen>, Oxid::Game::SplashScreen>]«:
/blabla/main/application.cpp:42:132:   instanced(?) from here
/usr/include/boost/preprocessor/iteration/detail/local.hpp:43:1: Error: no matching function for calling »Oxid::Game::SplashScreen::SplashScreen(const sf::RenderWindow&, const Oxid::System::FileSystem&, const Oxid::System::InputManager&)«
/usr/include/boost/preprocessor/iteration/detail/local.hpp:43:1: Anmerkung: candidates are :
../include/splashscreen.h:16:17: Anmerkung: Oxid::Game::SplashScreen::SplashScreen(sf::RenderWindow&, Oxid::System::FileSystem&, Oxid::System::InputManager&)
../include/splashscreen.h:16:17: Anmerkung:   no known conversion for argument 1 from »const sf::RenderWindow« to »sf::RenderWindow&«
../include/splashscreen.h:13:15: Anmerkung: Oxid::Game::SplashScreen::SplashScreen(const Oxid::Game::SplashScreen&)
../include/splashscreen.h:13:15: Anmerkung:   candidate requires 1 Argument, 3 denoted 

boost 源代码并不表示参数被更改为 const 或类似的东西。我忽略了什么导致这种转换发生?

编辑:刚刚查看了实际的 boost 更改日志(我使用的是 1.48.0),但它们不包含有关此问题的任何内容。

问候

【问题讨论】:

    标签: c++ boost


    【解决方案1】:

    当我查看源代码时,它似乎确实通过 const 引用获取参数,大概是这样在大多数情况下您不会担心丢失 const。我相信在您的情况下,您将不得不直接在 ptr_map 上使用 insert 而不是帮助模板。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      • 2018-07-13
      • 1970-01-01
      • 2017-02-20
      • 1970-01-01
      • 2011-10-19
      • 2021-12-26
      相关资源
      最近更新 更多