stockListType.cpp: 58: instanziiert von hierFehler: passing 'const ...' 'als 'dieses' Argument' ...‘verwirft Qualifikations
/usr/include/c++/4.2.1/bits/stl_algo.h:91: error: passing ‘const stockType’ as ‘this’ argument of ‘bool stockType::operator<(const stockType&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:92: error: passing ‘const stockType’ as ‘this’ argument of ‘bool stockType::operator<(const stockType&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:94: error: passing ‘const stockType’ as ‘this’ argument of ‘bool stockType::operator<(const stockType&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:98: error: passing ‘const stockType’ as ‘this’ argument of ‘bool stockType::operator<(const stockType&)’ discards qualifiers
/usr/include/c++/4.2.1/bits/stl_algo.h:100: error: passing ‘const stockType’ as ‘this’ argument of ‘bool stockType::operator<(const stockType&)’ discards qualifiers
Oberhalb der Fehler ich habe und würde wie jemand, der mir erklärt, was es bedeutet. Ich löste den Fehler, indem ich eine Konstante vor den Überladeoperator stellte. Mein Programm war eine Börsenanwendung, die eine Datei gelesen hat, die eine Zeichenkette, 5 Doppel und ein int enthält. Wir sortieren das Programm nach den String-Symbolen und der Indexverstärkung. Das Buch beauftragte mich, Vektoren zu verwenden, um alle Daten zu speichern. Wie Sie unten sehen, vergleicht der Überladungsoperator jedes Symbol und sortiert es mithilfe der Sortierelementfunktion von Containern aus. Meine Frage ist, warum musste ich eine Konstante vor den Überlastoperator für> und < setzen. aber nicht für> =, < =, ==,! = Überlastoperatoren.
//function was declared in stockType.h and implemented in stockType.cpp
bool operator<(const stockType& stock)//symbol is a string
{
return (symbols < stock.symbols)
}
//The function below was defined in stockListType.h and implemented in
// stockListType.cpp where I instantiated the object of stockType as a vector.
//vector<stockType> list; was defined in stockListType.h file
void insert(const& stockType item)
{
list.push_back(item);
}
void stockListType::sortStockSymbols()
{
sort(list.begin(), list.end());
}
'const & stockType sollte item' sein:' const stockType & item' – billz
OK Vielen Dank Jungs, die ich es zu schätzen wissen – Emy