boost::interprocess map: no appropriate default constructor compile error

Hello, I have a problem when compiling code using boost::interprocess library code. I've run into a compile error while trying to create a map in a boost shared memory object. I am using the VisualStudio2005 C++ compiler, and boost 1.38. The symptom is: C:\svn\ThirdPartySDK\boost_1_38_0\boost/interprocess/containers/map.hpp( 140) : error C2512: 'boost::interprocess::allocator<T,SegmentManager>::allocator' : no appropriate default constructor available with [ T=std::pair<sage::lib::clientDataServer::MapKey<10>,sage::lib::clientDat aServer::Data>, SegmentManager=boost::interprocess::segment_manager<char,boost::interpro cess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interpro cess::iset_index> ] Quick description - code is attached below: templated class ReadOnlyCatalog, taking an int template LENGTH and a template parm class T (T is the mapped data, or "second" in the pair). the map index is a templated class called MapKey, taking an int LENGTH. templated class MapKeyLess to provide the less() operator for the map index. Can anyone tell why am I getting the compiler error? Your help is greatly appreciated. template <int LENGTH, class T> class ReadOnlyCatalog { public: typedef std::pair<MapKey<LENGTH>, T> Value_t; typedef boost::interprocess::allocator<Value_t, boost::interprocess::managed_shared_memory::segment_manager> Allocator_t; typedef boost::interprocess::map<MapKey<LENGTH>, T, MapKeyLess<LENGTH>, Allocator_t> Map_t; ReadOnlyCatalog() { ... } ReadOnlyCatalog( const RoShMemType_e in_type, const std::string& in_segName, const std::string& in_objName ) { ... } }; const int OrderTypeKeyLength = 10; class Data { public: Data() { ... }; } template <int LENGTH> class MapKey { public: MapKey() { .. } MapKey( const std::string& in_key ) { ... } public: char m_key[LENGTH + 1]; }; template <int LENGTH> class MapKeyLess { public: bool operator()( const MapKey<LENGTH>& a, const MapKey<LENGTH>& b ) const { return strncmp( a.m_key, b.m_key, LENGTH ) < 0; } }; // instantiate ReadOnlyCatalog template; class OrderTypeCatalog : public ReadOnlyCatalog<OrderTypeKeyLength, Data> { public: OrderTypeCatalog() {} OrderTypeCatalog( const RoShMemType_e in_type, const std::string& in_segName, const std::string& in_objName ) : ReadOnlyCatalog( in_type, in_segName, in_objName ) {}; }; // a use of OrderTypeCatalog class X { public: X() { ptr = new OrderTypeCatalog( in_type, "aaa", "bbb" ); } private: OrderTypeCatalog* ptr; }; Included headers: #include <boost/interprocess/shared_memory_object.hpp> #include <boost/interprocess/mapped_region.hpp> #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/vector.hpp> #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/allocators/allocator.hpp> Full compiler error message: C:\svn\ThirdPartySDK\boost_1_38_0\boost/interprocess/containers/map.hpp( 140) : error C2512: 'boost::interprocess::allocator<T,SegmentManager>::allocator' : no appropriate default constructor available with [ T=std::pair<sage::lib::clientDataServer::MapKey<10>,sage::lib::clientDat aServer::Data>, SegmentManager=boost::interprocess::segment_manager<char,boost::interpro cess::rbtree_best_fit<boost::interprocess::mutex_family>,boost::interpro cess::iset_index> ] C:\svn\Projects\trunk\Lib/ClientDataServer/ReadOnlySegments.h(166) : while compiling class template member function 'sage::lib::clientDataServer::ReadOnlyCatalog<LENGTH,T>::ReadOnlyCatalog (void)' with [ LENGTH=10, T=sage::lib::clientDataServer::Data ] C:\svn\Projects\trunk\Lib/CLientDataServer/ReadOnlyShMem.h(25) : see reference to class template instantiation 'sage::lib::clientDataServer::ReadOnlyCatalog<LENGTH,T>' being compiled with [ LENGTH=10, T=sage::lib::clientDataServer::Data ] Regards, Chris Miclea

El 22/03/2010 20:43, Chris Miclea escribió:
Hello,
I have a problem when compiling code using boost::interprocess library code.
The compiler says it all. The shared memory allocator has no default constructor, so you must provide the allocator when constructing the map. See Interprocess documentation to see how to construct a map. http://www.boost.org/doc/libs/1_42_0/doc/html/interprocess/quick_guide.html#... Ion
participants (2)
-
Chris Miclea
-
Ion Gaztañaga