Error message: 'value_type': not a member

I do not understand this cryptic error message, but I get 30 of

`'value_type' : is not a member of 'TextFileLineBuffer'` 

when I compiled the following code in VC ++ 6 with //*** lines without comment.

Of course, if I commented on this, it compiles fine.

I think I tried different attempts in vain for the last two hours. Any advice would be appreciated.

 #include <list> #include <string> #include <iostream> #include <fstream> #include <algorithm> #include <iterator> //wrapper for a string line struct TextLine { std::string m_sLineContent; operator std::string const& () const { return m_sLineContent; } friend std::istream& operator>>(std::istream& stream, TextLine& line) { return std::getline(stream, line.m_sLineContent); } }; //this is a version of fixed size of string queue for easy text file reading class TextFileLineBuffer { public: TextFileLineBuffer(size_t lc, const char* fileName) : m_iLineCount(lc), m_sFileName(fileName) { std::ifstream file(fileName); //*** std::copy(std::istream_iterator<TextLine>(file), //*** std::istream_iterator<TextLine>(), //*** std::back_inserter(*this)); } void push_back(std::string const& line) { m_sBuffer.insert(m_sBuffer.end(),line); if (m_sBuffer.size() > m_iLineCount) { m_sBuffer.erase(m_sBuffer.begin()); } } const char* c_str() const { std::string returnValue(""); for (const_iterator it = begin(); it != end(); ++it) { returnValue = returnValue + *it; } return returnValue.c_str(); } typedef std::list<std::string> Container; typedef Container::const_iterator const_iterator; typedef Container::const_reference const_reference; const_iterator begin() const { return m_sBuffer.begin(); } const_iterator end() const { return m_sBuffer.end();} private: size_t m_iLineCount; std::list<std::string> m_sBuffer; std::string m_sFileName; }; 
+4
source share
2 answers

According to the standard ( 24.5.2.1 [back.insert.iterator] ), back_insert_iterator requires your Container type to contain a value_type typedef, which must be called the base argument type (const reference or rvalue reference) before push_back :

 class TextFileLineBuffer { public: // ... typedef std::string value_type; 

For compatibility with C ++ 98, you must also define const_reference , per std :: back_inserter requires const_reference for the older GCC. Why ?

  typedef const std::string &const_reference; 
+5
source

I found my way here because I tried to do this:

 std::vector<Type_A, Type_B> someVec; 

When I wanted to do this:

 std::vector<std::pair<Type_A, Type_B>> someVec; 

If your case is similar, keep in mind that the second boilerplate type for the stl container indicates a memory allocator that has special requirements. One of them is that it defines value_type .

0
source

Source: https://habr.com/ru/post/1436404/


All Articles