首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么boost::assign::ptr_map_insert将构造函数参数调用更改为常量引用?

为什么boost::assign::ptr_map_insert将构造函数参数调用更改为常量引用?
EN

Stack Overflow用户
提问于 2012-07-12 01:26:07
回答 1查看 244关注 0票数 1

我被以下行为搞糊涂了:

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

代码语言:javascript
复制
boost::assign::ptr_map_insert<SplashScreen>(screenContainer_)(GameScreens::Splash, curWindow_, curFileSystem_, curInputManager_);

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

curWindow_等是我的类"Application“的非常数私有成员

我不知道为什么,但GCC报告了一个错误,因为传递给构造函数的参数是常量引用,而SplashScreen的构造函数需要常规引用。

代码语言:javascript
复制
SplashScreen(sf::RenderWindow& curWindow, System::FileSystem& curFileSystem, System::InputManager& curInputManager);

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

代码语言:javascript
复制
/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 changelog (我使用的是1.48.0),但它们并没有包含关于这个问题的内容。

问候

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-12 01:54:12

当我查看源代码时,它似乎确实采用了const引用的参数,因此在大多数情况下,您可能不会担心丢失const。我相信在您的情况下,您将不得不直接在ptr_map上使用insert,而不是助手模板。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11438092

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档