What's this error mean?

This is a discussion on What's this error mean? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to build some 3rd party code and I'm getting an error: ValueToString.cpp:70: error: ‘std::basic_string::size_type’ is not a type ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    184

    What's this error mean? size_type not a type in template?

    I'm trying to build some 3rd party code and I'm getting an error:

    ValueToString.cpp:70: error: ‘std::basic_string::size_type’ is not a type

    The offending code:
    Code:
     template <class T> static void ensureCapacity(std::basic_string<T>& buffer,
                                                   std::basic_string<T>::size_type extraChars)
     {
       std::basic_string<T>::size_type requiredCapacity = buffer.length() + extraChars;
       if (requiredCapacity > buffer.capacity())
       {
         buffer.reserve(2 * requiredCapacity);
       }
     }
    I don't see what the error is!
    Last edited by 6tr6tr; 10-22-2008 at 05:46 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,325
    It means you need to add typename at the front of that phrase to indicate that std::basic_string<T>::size_type is referring to a type. Because it is based on T which could be anything, the compiler doesn't know whether size_type is a type or something else there. Adding typename resolves the ambiguity.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    184
    So is this the correct code? I added typename in two places:

    Code:
     template <class T> static void ensureCapacity(std::basic_string<T>& buffer,
                                                   typename std::basic_string<T>::size_type extraChars)
     {
       typename std::basic_string<T>::size_type requiredCapacity = buffer.length() + extraChars;
       if (requiredCapacity > buffer.capacity())
       {
         buffer.reserve(2 * requiredCapacity);
       }
     }

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,325
    I think so. Those are the only two places I notice.

    Does it fix the error?

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21