为什么boost::assign::ptrmap_insert将构造函数参数调用更改为const引用
why does boost::assign::ptr_map_insert changes constructor argument calls to const references?
我被以下行为弄糊涂了:
我的类"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
,而不是助手模板。
相关文章:
- 以线程安全的方式调用"QQuickPaintedItem::updateImage(const QImage&image)"(no QThread)
- 使用共享指针的函数调用,其对象应为 const
- 如何从构造函数副本 T(const T&)调用对象 T?
- 不允许运算符 const 参数调用 const 成员函数
- 为什么我的编译器在调用 const getter 函数时抛出"转换丢失(const)限定符"错误?
- 在循环条件中调用const vector size()似乎缺少优化
- 非常量调用 const 成员函数失败,只读位置C++
- 如何在模拟期望中调用const std::function<>&参数?
- 编译器如何知道是否调用 const 重载
- 从非const对象调用const函数
- 哈希映射错误:与调用 '(const __gnu_cxx::.
- 如何从析构函数调用const成员函数
- 如何强制调用 const 限定的函数重载
- 调用 const 对象时的类成员函数行为
- 构造函数何时调用 const-expr
- 没有调用const指针到指针的匹配函数
- 如何显式调用const版本的成员函数
- 正确的oop设计,如果我想调用const引用的非const函数
- 函数重载std::函数参数:为什么从未调用const方法
- 正在调用Const函数指针