-------------------------------------------------------------------- platform: g++ on timberlake file: SList.h---an early version where I had bodies outside the class error: [Whole screenfuls, not itemized any further with "error:"] SList.h:43: error: declaration of ‘operator*’ as non-function SList.h:43: error: expected ‘;’ before ‘const’ cause: I wrote I& operator* const; without the () SList.h: In constructor ‘SList::Cell::Cell()’: SList.h:97: error: class ‘SList::Cell’ does not have any field named ‘item’ SList.h: In constructor ‘SList::Cell::Cell(const I&, SList::Cell*)’: SList.h:103: error: class ‘SList::Cell’ does not have any field named ‘item’ cause: I wrote "item" when "data was the name of the field SList.h: At global scope: SList.h:118: error: expected initializer before ‘const’ Same missing () with operator* SList.h:123: error: expected constructor, destructor, or type conversion before ‘&’ token SList.h:130: error: expected constructor, destructor, or type conversion before ‘SList’ cause: Ah! "typename" *is* needed before a return type, as well as when declaring a field in the class SList.h:138: error: prototype for ‘bool SList::iterator::operator==(const SList::iterator&)’ does not match any in class ‘SList::iterator’ SList.h:46: error: candidate is: bool SList::iterator::operator==(const SList::iterator&) const SList.h:138: error: template definition of non-template ‘bool SList::iterator::operator==(const SList::iterator&)’ cause: I forgot to include the "const" in the outside-class portion for iterator's operator== SList.h:143: error: prototype for ‘bool SList::iterator::operator!=(const SList::iterator&)’ does not match any in class ‘SList::iterator’ SList.h:47: error: candidate is: bool SList::iterator::operator!=(const SList::iterator&) const SList.h:143: error: template definition of non-template ‘bool SList::iterator::operator!=(const SList::iterator&)’ cause: ditto for operator!= SList.h:152: error: expected constructor, destructor, or type conversion before ‘<’ token template SLIst::SList() : head (new Cell(I(), NULL)) , tail(head) , numItems(0) { } cause: I spelled SLIst with a capital I in the scope-specifier part of the constructor SList.h:159: error: expected class-name before ‘(’ token cause: I had "virtual ~SList()" instead of "SList::~SList()" SList.h:165: error: expected constructor, destructor, or type conversion before ‘SList’ SList.h:175: error: expected constructor, destructor, or type conversion before ‘SList’ cause: Needed "typename" again to start the line in both places SList.h:195: error: expected constructor, destructor, or type conversion before ‘SList’ SList.h:200: error: expected constructor, destructor, or type conversion before ‘SList’ cause: Ditto for "begin()" and "end()". Wow, from line 175 to 195 no errors! SList.h:217: error: prototype for ‘std::string SList::str()’ does not match any in class ‘SList’ SList.h:73: error: candidate is: std::string SList::str() const SList.h:217: error: template definition of non-template ‘std::string SList::str()’ cause: Missing "const" again SList.h: In member function ‘std::string SList::str()’: SList.h:221: error: expected `;' before ‘itr’ SList.h:222: error: ‘itr’ was not declared in this scope cause: Amazingly, I suspect the culprit was on the previous line: SList::iterator itr = begin(); needs the "typename" in front. SList.h: At global scope: SList.h:242: error: expected ‘,’ or ‘...’ before ‘&’ token SList.h:242: error: ISO C++ forbids declaration of ‘iterator’ with no type template void insert(const iterator& pos, const I& item) { cause: Outside class, one always needs the jawbreaker prefix: Fix is template void insert(const SList::iterator& pos, const I& item) { Does one need "typename" in a parameter too? I'll find out! SList.h: In function ‘void insert(int)’: SList.h:243: error: ‘pos’ was not declared in this scope SList.h:243: error: expected type-specifier before ‘Cell’ SList.h:243: error: expected `;' before ‘Cell’ SList.h:244: error: ‘numItems’ was not declared in this scope cause: Seemed to be all related to line 242. SList.h: At global scope: SList.h:253: error: expected constructor, destructor, or type conversion before ‘SList’ SList.h:264: error: expected constructor, destructor, or type conversion before ‘SList’ cause: Missing "typename" before return type again. -------------------------------------------------------------------------------- platform: g++ on timberlake file: SList.h---an early version where I had bodies outside the class Next try after the above fixes: timberlake g++ -c SList.h SList.h: In member function ‘I& SList::iterator::operator*() const’: SList.h:119: error: ‘data’ was not declared in this scope cause: Indeed, I had template I& SList::iterator::operator*() const { return data; } This was masked by the previous error with the missing ()s, so it didn't come last time. The field "data" is a field of Cell, not iterator. The iterator class for this single linked list has felds curr and item. So fix is: template I& SList::iterator::operator*() const { return current->data; } SList.h: At global scope: SList.h:195: error: expected constructor, destructor, or type conversion before ‘SList’ SList.h:200: error: expected constructor, destructor, or type conversion before ‘SList’ cause: forgot to add the typename's SList.h:242: error: expected unqualified-id before ‘&’ token SList.h:242: error: expected ‘,’ or ‘...’ before ‘&’ token SList.h:242: error: ISO C++ forbids declaration of ‘parameter’ with no type SList.h: In function ‘void insert(int)’: SList.h:243: error: ‘pos’ was not declared in this scope SList.h:243: error: expected type-specifier before ‘Cell’ SList.h:243: error: expected `;' before ‘Cell’ SList.h:244: error: ‘numItems’ was not declared in this scope cause: Ah, there was more wrong with those lines. I had: template void insert(const SList::iterator& pos, const I& item) { The SList:: prefix was missing before "insert". Fix is: template void SList::insert(const SList::iterator& pos, const I& item) { SList.h: In member function ‘typename SList::iterator SList::lower_bound(const I&)’: SList.h:254: error: expected `;' before ‘itr’ cause: More missing typename's. This message is especially instructive: I had SList::iterator itr = begin(); itr = begin(); cause: Without "typename", g++ is really expecting SList::iterator; As if that's a what, exactly? The remaining errors were related to the same. SList.h:255: error: ‘itr’ was not declared in this scope SList.h:258: error: ‘itr’ was not declared in this scope SList.h: In member function ‘typename SList::iterator SList::upper_bound(const I&)’: SList.h:265: error: expected `;' before ‘itr’ SList.h:266: error: ‘itr’ was not declared in this scope ----------------------------------------------------------- platform: g++ on timberlake file: SList.h---early version timberlake g++ -c SList.h SList.h: In member function ‘I& SList::iterator::operator*() const’: SList.h:119: error: ‘current’ was not declared in this scope timberlake cause: Silly typing error: field is just "curr" Then it compiled! [Warning: g++ -c SList.h by itself gives a HUGE file with the suffix .gch for "Gnu Compiled Header"!] ----------------------------------------------------------------------------- platform: g++ on timberlake file: extending my PhraseKWR file PhraseKWR.cpp:143: error: cannot declare member function ‘static bool Phrase::endWord(std::string)’ to have static linkage /** Illustrates find_first_of and string::npos. */ static bool Phrase::endWord(string word) { if ((size_t sz = word.size) == 0) { cause: static is not allowed here, outside the class! PhraseKWR.cpp:144: error: expected primary-expression before ‘sz’ PhraseKWR.cpp:144: error: expected `)' before ‘sz’ PhraseKWR.cpp:146: error: expected `)' before ‘else’ PhraseKWR.cpp:150: error: expected primary-expression before ‘}’ token PhraseKWR.cpp:150: error: expected `;' before ‘}’ token cause: can't do declaration inside if (...) clause: if ((size_t sz = word.size()) == 0) { -------------------------------------------------------------------- platform: g++ on timberlake file: making SListDriver.cpp SListDriver.cpp: In function ‘int main(int, char**)’: SListDriver.cpp:98: error: ‘phrase’ was not declared in this scope SList.h: In member function ‘typename SList::iterator SList::begin() const [with I = Phrase]’: SList.h:221: instantiated from ‘std::string SList::str() const [with I = Phrase]’ SListDriver.cpp:103: instantiated from here SList.h:196: error: dependent-name ‘SList::iterator’ is parsed as a non-type, but instantiation yields a type SList.h:196: note: say ‘typename SList::iterator’ if a type is meant SList.h: In member function ‘typename SList::iterator SList::end() const [with I = Phrase]’: SList.h:222: instantiated from ‘std::string SList::str() const [with I = Phrase]’ SListDriver.cpp:103: instantiated from here SList.h:201: error: dependent-name ‘SList::iterator’ is parsed as a non-type, but instantiation yields a type SList.h:201: note: say ‘typename SList::iterator’ if a type is meant SList.h: In member function ‘typename SList::iterator& SList::iterator::operator++() [with I = Phrase]’: SList.h:229: instantiated from ‘std::string SList::str() const [with I = Phrase]’ SListDriver.cpp:103: instantiated from here SList.h:126: error: invalid initialization of non-const reference of type ‘SList::iterator&’ from a temporary of type ‘SList::iterator* const’ cause: Well, the last on line 126 of SList.h is important, but let's see where the compiler complained about "typename" first: Line 196 of SList.h *which compiled alone* is: template typename SList::iterator SList::begin() const { return SList::iterator(head,head->next); } Wow---so even a constructor invocation needs the typename! It turned out to be needed on line 169 too: /** Add item, maintaining CLASS INV: linked list is sorted by lessThan. Adds at first permissible location, does not check for duplicates. */ template typename SList::iterator SList::insert(const I& item) { typename SList::iterator itr = lower_bound(item); typename SList::Cell* prev = itr.prev; insert(itr,item); //private version return typename SList::iterator(prev,prev->next); } lines around 196 must be: template typename SList::iterator SList::begin() const { return typename SList::iterator(head,head->next); } template typename SList::iterator SList::end() const { return typename SList::iterator(tail,tail->next); } The other error related to the hole in the project design. Morally we want the iterator to be const for this application: vector::const_iterator itr = items.begin(); vector::const_iterator iend = items.end(); since we were just reading from items, but the SList class does not create a const_iterator. Now we hit the serious error: timberlake g++ SListDriver.cpp SList.h: In member function ‘void SList::insert(const SList::iterator&, const I&) [with I = Phrase]’: SList.h:168: instantiated from ‘typename SList::iterator SList::insert(const I&) [with I = Phrase]’ SListDriver.cpp:98: instantiated from here SList.h:247: error: assignment of data-member ‘SList::iterator::prev’ in read-only structure SList.h: In member function ‘typename SList::iterator& SList::iterator::operator++() [with I = Phrase]’: SList.h:229: instantiated from ‘std::string SList::str() const [with I = Phrase]’ SListDriver.cpp:103: instantiated from here SList.h:126: error: invalid initialization of non-const reference of type ‘SList::iterator&’ from a temporary of type ‘SList::iterator* const’ timberlake Line 126 is "return this;" It should have been "return *this;" Why did SList.h file compile with that error?? That still left: timberlake g++ SListDriver.cpp SList.h: In member function ‘void SList::insert(const SList::iterator&, const I&) [with I = Phrase]’: SList.h:168: instantiated from ‘typename SList::iterator SList::insert(const I&) [with I = Phrase]’ SListDriver.cpp:98: instantiated from here SList.h:247: error: assignment of data-member ‘SList::iterator::prev’ in read-only structure /** Insert before cell "pos" is on. */ template void SList::insert(const SList::iterator& pos, const I& item) { pos.prev->next = new Cell(item, pos.curr); numItems++; // Should re-validate pos---stays on cell *after* one inserted. // Hence pos.prev should be the new cell pos.prev = pos.prev->next; } And this is a total gotcha!! *Morally*, the iterator is not invalidated by the insert. However, this particular implementation needs a "prev" field. The insert goes between the prev and curr fields, meaning what we have to re-set the former to the new node...but we can't since "pos" is const. "Fixed" only by allowing the private version to be non-const. ----------------------------------------------------- platform: g++ on timberlake file: SListDriver.cpp sample client file error: timberlake g++ SListDriver.cpp SList.h: In member function ‘void SList::erase(SList::iterator) [with I = Phrase]’: SListDriver.cpp:121: instantiated from here SList.h:194: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits](((std::basic_ostream >&)(& std::cerr)), ((const char*)"Deleting: ")) << curr->SList::Cell::data’ /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:67: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:78: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:90: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:241: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:264: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:102: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:125: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:157: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:183: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:215: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:288: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:311: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:361: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:335: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:384: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:407: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits] /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/ostream.tcc:430: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits] timberlake cause: I wrote "<< data" not "<< data.str()" That was all---then it compiled! -------------------------------------------------------------- ---------------------------------------------------------- platform: g++ on timberlake, *with* the gfilt filter. file: Mainly ValliWrap.h, version of Project 1 answer for the "adventurous third option" of wrapping std::list like the text does. error: make -f Valli.make /util/bin/gfilt -O5 -Wall -c ValliDriver.cpp BD Software STL Message Decryptor v3.10 for gcc 2/3/4 ValliWrap.h:29: error: type ‘list’ is not derived from type ‘Valli< I>’ ValliWrap.h:29: error: expected ‘;’ before ‘iterator’ ValliWrap.h:32: error: ‘iterator’ was not declared in this scope ValliWrap.h:32: error: template argument 1 is invalid ValliWrap.h:32: error: template argument 2 is invalid cause: I had written typedef list::iterator iterator; It needed to be typedef typename list::iterator iterator; Are you freakin' kidding me, g++??? Even in a "typedef", you can't tell that list::iterator names a type?? What are you made of, cuckoo clock chimes? That cerated a knock-on effect, so ignore the rest: ValliWrap.h:78: error: ‘iterator’ does not name a type ValliWrap.h:101: error: ‘iterator’ does not name a type ValliWrap.h:120: error: ‘iterator’ has not been declared ValliWrap.h:136: error: ‘iterator’ does not name a type ValliWrap.h:139: error: ‘iterator’ does not name a type ValliWrap.h:188: error: expected ‘, ’ or ‘...’ before ‘&’ token ValliWrap.h:188: error: ISO C++ forbids declaration of ‘iterator’ with no type ValliWrap.h:219: error: ‘iterator’ does not name a type ValliWrap.h:230: error: ‘iterator’ does not name a type ValliWrap.h: In constructor ‘Valli::Valli()’: ValliWrap.h:46: error: missing template arguments before ‘( ’ token ValliWrap.h:47: error: ‘iterator’ was not declared in this scope ValliWrap.h:47: error: template argument 1 is invalid ValliWrap.h:47: error: template argument 2 is invalid ValliWrap.h:52: error: request for member ‘push_back’ in ‘( (Valli *)this)->Valli::vec->’, which is of non-class type ‘ int’ ValliWrap.h:53: error: request for member ‘push_back’ in ‘( (Valli *)this)->Valli::vec->’, which is of non-class type ‘ int’ ValliWrap.h: In constructor ‘Valli::Valli(size_t)’: ValliWrap.h:58: error: missing template arguments before ‘( ’ token ValliWrap.h:59: error: ‘iterator’ was not declared in this scope ValliWrap.h:59: error: template argument 1 is invalid ValliWrap.h:59: error: template argument 2 is invalid ValliWrap.h:64: error: request for member ‘push_back’ in ‘( (Valli *)this)->Valli::vec->’, which is of non-class type ‘ int’ ValliWrap.h:65: error: request for member ‘push_back’ in ‘( (Valli *)this)->Valli::vec->’, which is of non-class type ‘ int’ ValliWrap.h: In member function ‘void Valli::erase(int)’: ValliWrap.h:121: error: invalid type argument of ‘unary *’ ValliWrap.h:122: error: ‘iterator’ was not declared in this scope ValliWrap.h:122: error: expected `;' before ‘headItr’ ValliWrap.h:123: error: ‘headItr’ was not declared in this scope ValliWrap.h: In member function ‘void Valli::refresh(size_t)’: ValliWrap.h:150: error: request for member ‘clear’ in ‘((Valli *) this)->Valli::vec->’, which is of non-class type ‘int’ ValliWrap.h:151: error: ‘iterator’ was not declared in this scope ValliWrap.h:151: error: expected `;' before ‘itr’ ValliWrap.h:153: error: ‘itr’ was not declared in this scope ValliWrap.h:155: error: request for member ‘push_back’ in ‘( (Valli *)this)->Valli::vec->’, which is of non-class type ‘ int’ ValliWrap.h:160: error: request for member ‘push_back’ in ‘( (Valli *)this)->Valli::vec->’, which is of non-class type ‘ int’ ValliWrap.h:160: error: ‘itr’ was not declared in this scope ---------------------------- platform: g++/gfilt on timberlake file: ValliWrap.cpp BD Software STL Message Decryptor v3.10 for gcc 2/3/4 ValliWrap.h: In constructor ‘Valli::Valli()’: ValliWrap.h:46: error: missing template arguments before ‘( ’ token I had written : theList(list()) Needs to be : theList(list()) When you *call* a templated constructor, you *always* need the <...> ValliWrap.h: In constructor ‘Valli::Valli(size_t)’: ValliWrap.h:58: error: missing template arguments before ‘( ’ token Ditto. ValliWrap.h: In member function ‘string Valli::str() const’: ValliDriver.cpp:90: instantiated from here ValliWrap.h:168: error: conversion from ‘list::const_iterator’ to non-scalar type ‘list::iterator’ requested An *impt* point: The str() function is /const/, and hence the iterator you get must be declared a const_iterator: iterator itr = theList.begin(); needs to be const_iterator itr = theList.begin(); Does this work??? ValliWrap.h: In member function ‘list< Phrase>::iterator Valli::insert(const Phrase &)’: ValliDriver.cpp:101: instantiated from here ValliWrap.h:85: error: conversion from ‘void’ to non-scalar type ‘list< Phrase>::iterator’ requested I had forgotten my own project spec: I had void insert(const iterator& pos, const I& item) { but need to return an iterator: /** Insert before cell "pos" is on. */ iterator insert(const iterator& pos, const I& item) { return theList.insert(pos,item); } ValliWrap.h: In member function ‘list::iterator Valli ::begin() const’: ValliDriver.cpp:115: instantiated from here ValliWrap.h:137: error: conversion from ‘list::const_iterator’ to non-scalar type ‘list::iterator’ requested ValliWrap.h: In member function ‘list::iterator Valli::end() const’: ValliDriver.cpp:137: instantiated from here ValliWrap.h:140: error: conversion from ‘list::const_iterator’ to non-scalar type ‘list::iterator’ requested The reason I called this option "adventurous". Because we are wrapping std::list, which returns const_iterators whenever it's const, we need to use const_iterators too. For the moment I casted-away const: iterator begin() const { return theList.begin(); } iterator end() const { return theList.end(); } became iterator begin() const { return (iterator)theList.begin(); } iterator end() const { return (iterator)theList.end(); } But as a cure for "const"ipation it's like eating a bucketful of prunes... ValliWrap.h: In member function ‘void Valli< Phrase>::erase(list::iterator)’: ValliDriver.cpp:140: instantiated from here ValliWrap.h:124: error: no match for ‘operator=’ in ‘*( ((Valli *)this)->Valli::vec + ( (vector::iterator> *)(i * 24u))) = headItr.list< Phrase>::iterator::operator++()’ I wrote vec[i] = ++headItr; forgetting that vec is a pointer. Fix is: vec->at(i) = ++headItr; ValliWrap.h: In member function ‘list< Phrase>::iterator Valli::find(const Phrase &) const’: ValliDriver.cpp:156: instantiated from here ValliWrap.h:102: error: passing ‘const Valli’ as ‘this’ argument of ‘size_t Valli::binsearch(const Phrase &)’ discards qualifiers I simply forgot to declare binsearch(...) const! It jolly well should be..;.and needs to be because find(...) is const and find(...) calls it. ValliDriver.cpp:156: instantiated from here ValliWrap.h:107: error: no match for ‘operator>’ in ‘itr.list ::iterator::operator *()> item’ Oops, I wrote: if (*itr > item) { Needs to be if (item < *itr) { C++ cannot "divine" that operator> is automatically the mirror-image of operator<. As is standard with the STL, the client defined only the latter. --------------------------------------------------------- ValliWrap.h: In member function ‘string Valli::str() const’: ValliWrap.h:168: error: ‘const_iterator’ was not declared in this scope ValliWrap.h:168: error: expected `;' before ‘itr’ ValliWrap.h:169: error: ‘itr’ was not declared in this scope ValliWrap.h: In member function ‘list::iterator Valli ::begin() const’: ValliDriver.cpp:115: instantiated from here ValliWrap.h:137: error: No match for ‘list< Phrase>::iterator(list::const_iterator)’ ValliWrap.h: In member function ‘list::iterator Valli::end() const’: ValliDriver.cpp:137: instantiated from here ValliWrap.h:140: error: No match for ‘list< Phrase>::iterator(list::const_iterator)’ OK, I couldn't get away with a generic "const_iterator itr = ..." declaration. I really need a typedef list::const_iterator const_iterator declaration too. Yes, *with* the barmy "typename" in front too! But first, more prunes...I changed line 168, const_iterator itr = theList.begin(); to iterator itr = (iterator)(theList.begin()); The other errors were because I forgot the second (...) enclosure---C++ gives (typecast) precedence over . membership! Nope---it still wouldn't let me cast-away the const! The reason is that "const_iterator" is a WHOLE DIFFERENT TYPE---it's not the same as "const iterator". So can the prunes. I had to remove the "const" from "begin" and "end". That still, however, left the problem on line 168 in the str() method, which must be const. For that I simply made it an explicit list::const_iterator: typename list::const_iterator itr = theList.begin(); I still got: ValliWrap.h: In member function ‘string Valli::str() const’: ValliDriver.cpp:90: instantiated from here ValliWrap.h:169: error: passing ‘const Valli’ as ‘this’ argument of ‘list::iterator Valli::end()’ discards qualifiers ValliWrap.h: In member function ‘list< Phrase>::iterator Valli::find(const Phrase &) const’: ValliDriver.cpp:156: instantiated from here ValliWrap.h:108: error: passing ‘const Valli’ as ‘this’ argument of ‘list::iterator Valli::end()’ discards qualifiers For the first, I needed to be consistent and change while (itr != end()) { to while (itr != theList.end()) { The other is more intractable. I had: iterator find(const I& item) const { size_t i = binsearch(item); iterator itr = vec->at(i); while (itr != theList.end() && *itr < item) { ++itr; } if (item < *itr) { return end(); I had taken the "const" off the Valli::end() function. Since find(...) is const---and jolly well must be---it can't call end() directly anymore. Note, by the way, that at http://cplusplus.com/reference/stl/multiset/find/ the find method has the consts, but returns just "iterator" NOT "const_iterator"! The fix was to avoid calling end() directly, but rather advance an iterator to the end. Handy: CLASS INV: vec[0] = theLIst.begin(), vec[s-1] = theList.end() so I just did return vec->back; Oops: BD Software STL Message Decryptor v3.10 for gcc 2/3/4 ValliWrap.h: In member function ‘list< Phrase>::iterator Valli::find(const Phrase &) const’: ValliDriver.cpp:156: instantiated from here ValliWrap.h:109: error: conversion from ‘’ to non-scalar type ‘list::iterator’ requested Forgot it's a function, not a member: return vec->back(); Then it all compiled! The one bug in my code itself was a bottomless recursion: void erase(iterator itr) { size_t i = binsearch(*itr); // auto-bombs if itr == end() iterator headItr = vec->at(i); if (itr == headItr) { vec->at(i) = ++headItr; // unnecessary if refresh but convenient } erase(itr); //oops! The last line needed to be a delegation: theList.erase(itr); BD Software STL Message Decryptor v3.10 for gcc 2/3/4 TimingDriver.cpp: In function ‘int main(int, char **)’: TimingDriver.cpp:121: error: No match for ‘i’ ValliNNN.h: In member function ‘Valli< Phrase>::iterator Valli::find(const Phrase &) const’: TimingDriver.cpp:210: instantiated from here ValliNNN.h:112: error: no match for ‘operator<’ in ‘( (const Valli *)this )->Valli< Phrase >::cellPointerVector.vector< Valli::iterator, allocator::iterator> > ::operator[](((long unsigned int)mid)) < item’ ValliNNN.h:115: error: no match for ‘operator<’ in ‘item < ( (const Valli *)this )->Valli< Phrase >::cellPointerVector.vector< Valli::iterator, allocator::iterator> > ::operator[](((long unsigned int)mid))’ ValliNNN.h: In member function ‘Valli::iterator Valli ::binarysearch(const Phrase &) const’: ValliNNN.h:86: instantiated from ‘Valli::iterator Valli ::insert(const Phrase &)’ TimingDriver.cpp:138: instantiated from here ValliNNN.h:249: error: no match for ‘operator<’ in ‘( (const Valli *)this )->Valli< Phrase >::cellPointerVector.vector< Valli::iterator, allocator::iterator> > ::operator[](((long unsigned int)mid)) < item’ ValliNNN.h:252: error: no match for ‘operator<’ in ‘item < ( (const Valli *)this )->Valli< Phrase >::cellPointerVector.vector< Valli::iterator, allocator::iterator> > ::operator[](((long unsigned int)mid))’ ValliNNN.h: In member function ‘void Valli::refresh()’: ValliNNN.h:94: instantiated from ‘Valli::iterator Valli ::insert(const Phrase &)’ TimingDriver.cpp:138: instantiated from here ValliNNN.h:142: error: No match for ‘vector< Valli::iterator, allocator::iterator> > ::push_back(Phrase &)’ The constructor Valli(int ratio) was missing, and mainly, the code was doing mileposts[i] < item, forgetting the * operator. BD Software STL Message Decryptor v3.10 for gcc 2/3/4 ValliNNN.h: In member function ‘void Valli::refresh()’: ValliNNN.h:108: instantiated from ‘Valli::iterator Valli ::insert(const Phrase &)’ TimingDriver.cpp:138: instantiated from here ValliNNN.h:156: error: No match for ‘vector< Valli::iterator, allocator::iterator> > ::push_back(Phrase &)’ Had cellPointerVector.push_back(*itr); meant cellPointerVector.push_back(itr); ------------------------------- ValliNNN.h: In constructor âValli::Valli() [with I = Phrase]â: ValliDriverNNN.cpp:91: instantiated from here ValliNNN.h:133: error: type âValliâ is not a direct base of âValliâ Code did Valli() : Valli(20), but C++ does not yet have this Java feature of forwarding constructors. Fix was to re-code the entire body of the other constructor, but fixing ratio=20. -------------------------------------------------------------- platform: g++ on timberlake ValliNNN.h: In constructor ¿Valli::Valli()¿: ValliDriver.cpp:92: instantiated from here ValliNNN.h:86: error: No match for ¿vector< Valli::iterator, allocator::iterator> > ::push_back(Valli::Cell *&)¿ ValliNNN.h:87: error: No match for ¿vector< Valli::iterator, allocator::iterator> > ::push_back(Valli::Cell *&)¿ ValliNNN.h: In member function ¿Valli< Phrase>::iterator Valli::find(const Phrase &) const¿: ValliDriver.cpp:160: instantiated from here ValliNNN.h:188: error: passing ¿const Valli¿ as ¿this¿ argument of ¿int Valli::binSearch(const Phrase &)¿ discards qualifiers ValliNNN.h: In member function ¿int Valli::binSearch(const Phrase &)¿: ValliNNN.h:188: instantiated from ¿Valli::iterator Valli ::find(const Phrase &) const¿ ValliDriver.cpp:160: instantiated from here ValliNNN.h:118: error: conversion from ¿Valli::iterator *¿ to non- scalar type ¿Valli::iterator¿ requested cause: initialized vector with "new" as if it was a pointer, but had declared as value. BD Software STL Message Decryptor v3.10 for gcc 2/3/4 ValliNNN.h: In constructor ¿Valli::Valli()¿: ValliDriver.cpp:92: instantiated from here ValliNNN.h:86: error: No match for ¿vector< Valli::iterator, allocator::iterator> > ::push_back(Valli::Cell *&)¿ ValliNNN.h:87: error: No match for ¿vector< Valli::iterator, allocator::iterator> > ::push_back(Valli::Cell *&)¿ ValliNNN.h: In member function ¿Valli< Phrase>::iterator Valli::find(const Phrase &) const¿: ValliDriver.cpp:160: instantiated from here ValliNNN.h:188: error: passing ¿const Valli¿ as ¿this¿ argument of ¿int Valli::binSearch(const Phrase &)¿ discards qualifiers ValliNNN.h: In member function ¿int Valli::binSearch(const Phrase &)¿: ValliNNN.h:188: instantiated from ¿Valli::iterator Valli ::find(const Phrase &) const¿ ValliDriver.cpp:160: instantiated from here ValliNNN.h:118: error: conversion from ¿Valli::iterator *¿ to non- scalar type ¿Valli::iterator¿ requested cause: ---first error was trying to store a Cell* object (head & tail) into a vector of iterators. Second error was not making binSearch const. platform: g++ on timberlake ValliNNN.h: In member function ¿void Valli::erase(Valli::iterator)¿: ValliNNN.h:228: error: expected primary-expression before ¿)¿ token make: *** [SListDriver.o] Error 1 cause: wrote itr* not *itr to get the item from the iterator platform: g++ on timberlake file: ValliNNN.h BD Software STL Message Decryptor v3.10 for gcc 2/3/4 ValliNNN.h: In member function ‘Valli< Phrase>::iterator Valli::find(const Phrase &) const’: ValliDriver.cpp:158: instantiated from here ValliNNN.h:152: error: passing ‘const Valli’ as ‘this’ argument of ‘int Valli< Phrase >::binarySearch( vector::iterator, allocator::iterator> >, int, int, const Phrase &)’ discards qualifiers ValliNNN.h: In member function ‘int Valli< Phrase >::binarySearch( vector::iterator, allocator::iterator> >, int, int, const Phrase &)’: ValliNNN.h:121: instantiated from ‘Valli::iterator Valli ::insert(const Phrase &)’ ValliDriver.cpp:103: instantiated from here ValliNNN.h:301: error: no match for ‘operator>=’ in ‘item>= ( ( Valli::iterator * )vec.vector< Valli::iterator, allocator::iterator> >::at(((long unsigned int)middle)))->Valli::iterator ::operator *()’ ValliNNN.h:307: error: no match for ‘operator>’ in ‘item> ( ( Valli::iterator * )vec.vector< Valli::iterator, allocator::iterator> >::at(((long unsigned int)middle)))->Valli::iterator::operator *()’ cause: student had assumed that having coded operator<, C++ would automatically carry over into operators >=, >, etc. fix: replace if (this >= that) by if (!(this < that)), and if (this > that) by if (that < this). --------------------------------------- platform: g++ on timberlake(?) cause: reported by student as occurring at run time after using a vector with square brackets (rather than the safer ".at") and running one past the bounds and then trying to read. *** glibc detected *** ./a.out: free(): invalid next size (fast): 0x0000000012840190 *** ======= Backtrace: ========= /lib64/libc.so.6[0x33c2c71cec] /lib64/libc.so.6(cfree+0x8c)[0x33c2c7590c] ./a.out[0x4028c7] ./a.out[0x4028f9] ./a.out[0x40293a] ./a.out[0x402a39] ./a.out[0x402ed4] ./a.out[0x4037a3] ./a.out[0x4018e7] /lib64/libc.so.6(__libc_start_main+0xf4)[0x33c2c1d974] ./a.out(__gxx_personality_v0+0x81)[0x401239] ======= Memory map: ======== 00400000-00406000 r-xp 00000000 00:17 3836554 /home/csdue/dbaratta/cse250/Projects/Project1New/a.out 00605000-00606000 rw-p 00005000 00:17 3836554 /home/csdue/dbaratta/cse250/Projects/Project1New/a.out 127b5000-1285a000 rw-p 127b5000 00:00 0 [heap] 33c2400000-33c241c000 r-xp 00000000 fd:00 63491 /lib64/ld-2.5.so 33c261b000-33c261c000 r--p 0001b000 fd:00 63491 /lib64/ld-2.5.so 33c261c000-33c261d000 rw-p 0001c000 fd:00 63491 /lib64/ld-2.5.so 33c2c00000-33c2d4c000 r-xp 00000000 fd:00 63494 /lib64/libc-2.5.so 33c2d4c000-33c2f4c000 ---p 0014c000 fd:00 63494 /lib64/libc-2.5.so 33c2f4c000-33c2f50000 r--p 0014c000 fd:00 63494 /lib64/libc-2.5.so 33c2f50000-33c2f51000 rw-p 00150000 fd:00 63494 /lib64/libc-2.5.so 33c2f51000-33c2f56000 rw-p 33c2f51000 00:00 0 33c3000000-33c3082000 r-xp 00000000 fd:00 63509 /lib64/libm-2.5.so 33c3082000-33c3281000 ---p 00082000 fd:00 63509 /lib64/libm-2.5.so 33c3281000-33c3282000 r--p 00081000 fd:00 63509 /lib64/libm-2.5.so 33c3282000-33c3283000 rw-p 00082000 fd:00 63509 /lib64/libm-2.5.so 33c8000000-33c800d000 r-xp 00000000 fd:00 63515 /lib64/libgcc_s-4.1.2-20080825.so.1 33c800d000-33c820d000 ---p 0000d000 fd:00 63515 /lib64/libgcc_s-4.1.2-20080825.so.1 33c820d000-33c820e000 rw-p 0000d000 fd:00 63515 /lib64/libgcc_s-4.1.2-20080825.so.1 33c8800000-33c88e6000 r-xp 00000000 fd:03 2687243 /usr/lib64/libstdc++.so.6.0.8 33c88e6000-33c8ae5000 ---p 000e6000 fd:03 2687243 /usr/lib64/libstdc++.so.6.0.8 33c8ae5000-33c8aeb000 r--p 000e5000 fd:03 2687243 /usr/lib64/libstdc++.so.6.0.8 33c8aeb000-33c8aee000 rw-p 000eb000 fd:03 2687243 /usr/lib64/libstdc++.so.6.0.8 33c8aee000-33c8b00000 rw-p 33c8aee000 00:00 0 2b3f1ca01000-2b3f1ca03000 rw-p 2b3f1ca01000 00:00 0 2b3f1ca26000-2b3f1ca29000 rw-p 2b3f1ca26000 00:00 0 2b3f20000000-2b3f20021000 rw-p 2b3f20000000 00:00 0 2b3f20021000-2b3f24000000 ---p 2b3f20021000 00:00 0 7fff80ef3000-7fff80f08000 rw-p 7ffffffea000 00:00 0 [stack] ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0 [vdso]