stockListType.cppの 『この』引数として:58:ここエラー:パッシング「のconst ...」「」...」修飾子を破棄し
以上/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
私が得たエラーであるとだろうからインスタンス誰かのように私にそれが何を意味するのか説明してください。オーバーロード演算子の前に定数を置くことでエラーを解決しました。私のプログラムは、文字列、5倍とintを含むファイルを読み込む株式市場のアプリケーションでした。文字列記号とインデックスゲインでプログラムを分類します。この本は私にベクトルを使って各データを保存するように指示しました。以下に示すように、オーバーロード演算子は各シンボルを比較し、コンテナのソートメンバー関数を使用してソートします。私の質問はなぜ>と<のオーバーロード演算子の前に定数を入れなければならなかったかです。 > =、< =、==、!=オーバーロード演算子ではありません。
//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 item'は次のようになります。'のconst stockType&item' – billz
OKおかげで私はそれを感謝し、多くの人たち – Emy