为什么boost::assign::ptrmap_insert将构造函数参数调用更改为const引用

why does boost::assign::ptr_map_insert changes constructor argument calls to const references?

本文关键字:调用 const 引用 参数 assign boost ptrmap 为什么 insert 构造函数      更新时间:2023-10-16

我被以下行为弄糊涂了:

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

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

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

curWindow_等是我的类"应用程序"的非常私人成员

我不知道为什么,但GCC报告了一个错误,因为传递给构造函数的参数是常量引用,而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),但它们没有包含关于这个问题的内容。

问候

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