I am confused by the following behavior:
My class “Application” adds in the constructor elements of the type “SplashScreen” (derived from my class “Screen ” which is the container type) using ptr_map_insert into a pointer container of the type Screen. Example:
boost::assign::ptr_map_insert<SplashScreen>(screenContainer_)(GameScreens::Splash, curWindow_, curFileSystem_, curInputManager_);
According to the documentation of ptr_map_insert, the last pair of brackets begins with the key and the following arguments are passed to the constructor of the SplashScreen class.
curWindow_ etc. are non-const private members of my class “Application”
I don’t know why, but GCC reports an error because the arguments passed to the constructor are const references and the constructor of SplashScreen needs regular references.
SplashScreen(sf::RenderWindow& curWindow, System::FileSystem& curFileSystem, System::InputManager& curInputManager);
The complete error message is below and partially translated by me because it is/was in german.
/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
The boost sourcecode doesn’t indicate that arguments are changed to const or something similar. What did I overlook that this conversion occurs?
Edit: Just viewed the actual boost changelog (I am using 1.48.0) but they don’t contain something about this problem.
Regards
As I look at the source it appears that it does take the parameters by const reference, presumably so that in most cases you don’t have loss-of-const concerns. I believe that in your case you’re going to have to use
insertdirectly on theptr_mapinstead of the helper template.