Std :: string with highlighting enabled
I have an allocator that allocates memory based on its instance variable MemoryContext
. I tried to create an std::string
allocator for this type. The header looks like this
class String {
private:
std::basic_string< char
, std::char_traits<char>
, MemoryContextAllocator<char> > my_string;
public:
explicit String( MemoryContext* memoryContext );
~String();
MemoryContextAllocator<char> getAllocator() const;
};
The source looks like this
String::String(MemoryContext* memoryContext)
:my_string( MemoryContextAllocator<char>(memoryContext) )
{
}
String::~String() {
}
At compile time I get an error like this
/usr/include/C++/4.8/bits/basic_string.tcc: 156: 27: error: no corresponding function to call
MemoryContextAllocator<char>::MemoryContextAllocator()
It tries to call the allocator constructor with no arguments. If I don't want to introduce this default constructor and use setters, how can I solve this problem?
source to share
No one has answered this question yet
Check out similar questions: