STL error messages are so great!!!

STL is a great library to use when programming with C++. It contains loads of helpful data structures (stacks, queues, lists, …) and a set of useful algorithms (sort, swap, min, max,…) which are efficiently implemented. However, there’s a major problem with STL; how to decipher the error message.

In the sample C++ program below, I have on purpose missed the iterator in the insert statement; instead of typing “aList.insert(aList.begin(),10);” I typed “aList.insert(10);”

Sample Program:

#include <iostream>
#include <vector>

using namespace std;

int main(){
      vector<int> aList;

       aList.insert(10);    // iterator purposely missed here

       return 0;
}

Error Message:

pascal@zetwal:~/temp$ g++ stltest.cpp
stltest.cpp: In function ‘int main()’:
stltest.cpp:9: error: no matching function for call to ‘std::vector<int, std::allocator<int> >::insert(int)’
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/vector.tcc:93: note: candidates are: typename std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(__gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = int, _Alloc = std::allocator<int>]
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/bits/stl_vector.h:657: note: void std::vector<_Tp, _Alloc>::insert(__gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, size_t, const _Tp&) [with _Tp = int, _Alloc = std::allocator<int>]

Do they seriously think I’m supposed to understand that???

12 responses to “STL error messages are so great!!!

  1. Apparently Herb Sutter is making strides to improve the error messages which is displayed when using templates although I think this only applies to MSVC and not the GCC suite…

  2. stltest.cpp:9: error: no matching function for call to ‘std::vector<int,

    alala bel problem!!! servi windows, gagne 1 sel erreur:

    ——————–Configuration: 1 – Win32 Debug——————–
    Compiling…
    1.cpp
    C:\Documents and Settings\User\Desktop\1.cpp(10) : error C2664: ‘int *__thiscall std::vector<int,class std::allocator >::insert(int *,const int &)’ : cannot convert parameter 1 from ‘const int’ to ‘int *’
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.

    1.exe – 1 error(s), 0 warning(s)

    😀😀

  3. well you get the line numbers in the beginning, that’s enough non?

    as for yasir… dude you’ve got some serious problem if you saw more than one errors in both cases.

    +$3|v3n

  4. @$3|v3n your situation is really critical if you don’t understand jokes😉 Well, as mentioned above, code is not complete so don’t expect a working code…..

    dude you’ve got some serious problem if you saw more than one errors in both cases.

    seems u have got some serious problems as u were not able to see only 1 error message(s)😀😀

  5. @ Selven

    “well you get the line numbers in the beginning, that’s enough non?”

    You are right; the first line says all about the error but the remaining is here it seems just to confuse you. The problem is when you have 3 or more error messages. You really get lost then.

    In these cases I prefer to discard the error message and look for the error around the line indicated.

  6. Sometime back I did see a tool which “decrypts” these error messages.

    I had a terrible time fixing errors in STL. There were plenty of them as I was migrating a huge project from VC6 to VC8 apparently plenty of warnings and errors. Was a great experience though!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s