"no type named 'const_reference' " error when implementing a string-like class

c++

Solution

It sounds like your `vec` doesn't meet the Container Requirements, so it's not guaranteed to be usable by standard facilities (such as `back_inserter`) that work with containers.

The requirements are specified in Table 96 in C++11, although Table 65 in C++98 is probably more appropriate for your ancient compiler. One of those requirements is a nested `const_reference` type.

Problem

I'm trying to implement a class with similar behavior to std::string and I'm getting the error in the std::copy line: ``` Str& operator+=(const Str& s){ std::copy(s.data.begin(), s.data.end(), std::back_inserter(data)); return *this; } ``` 'data' is an object of type vec < char> , and vec is a vector-like class that I implemented myself and it seems to be working fine on its own. It also says this: C:\MinGW\bin..\lib\gcc\mingw32\3.4.2........\include\c++\3.4.2\bits\stl_iterator.h||In instantiation of `std::back_insert_iterator < vec< char> >':|

Original source

Related problems