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::allocator' : no
appropriate default constructor available
with
[
T=std::pair,sage::lib::clientDat
aServer::Data>,
SegmentManager=boost::interprocess::segment_managerboost::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
class ReadOnlyCatalog
{
public:
typedef std::pair Value_t;
typedef boost::interprocess::allocator
Allocator_t;
typedef boost::interprocess::map 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
{
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
#include
#include
#include
#include
#include
Full compiler error message:
C:\svn\ThirdPartySDK\boost_1_38_0\boost/interprocess/containers/map.hpp(
140) : error C2512:
'boost::interprocess::allocator::allocator' : no
appropriate default constructor available
with
[
T=std::pair,sage::lib::clientDat
aServer::Data>,
SegmentManager=boost::interprocess::segment_managerboost::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::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' being compiled
with
[
LENGTH=10,
T=sage::lib::clientDataServer::Data
]
Regards,
Chris Miclea