LoginSignup
1
3

目的

C++に限らず、コンパイルエラーがたくさん出るとめげる。
根本原因のエラーと、それに付属する関連エラーがあり、
根本原因エラーさえ取れば、みんなきれさっぱりなくなることがある。

複数のファイルにまたがるエラーは、相互に影響があり、どちらを直すとより効率的かを判断できないと無駄な作業が発生するかもしれない。

効率的にコンパイルエラーを取る方法を探るため、コンパイルエラー情報とその際の対応方法を収集する。

成果

コンパイルエラーとその時の条件に従い、すぐにコンパイルエラーが取れるようになる。

コンパイルエラーが取れれば、printf(cout)デバッグができるかもしれない。

関連

悲しいのはprintf(cout)デバッグをしようとすると、コンパイルエラーが出る時。

printf(cout)デバッグをしてもコンパイルエラーが出ない方法も順次追記する。

複雑な構造を持った新たなclassは、直接coutしようとせず、よく知った必要な型に変換して出力するのも手かも。

castしようとすると、castのコンパイルエラーが出るかもしれない。
castでコンパイルエラーが出ない方法を知っているとよい。

一覧

C++ Error Message Collection(1)does not name a type, 11 articles
https://qiita.com/drafts/acb9f1a9b5aad6df06bd

C++ Error Message Collection(2)expected unqualified-id, 11 articles
https://qiita.com/kaizen_nagoya/items/bccd7341a5ce58e94370

(3) invalid operands to binary expression

3.1 error:Invalid operands to binary expression ('struct Number' and 'struct Number')

Invalid operands to binary expression エラーの対処方法
http://marycore.jp/prog/xcode/invalid-operands-to-binary-expression/

原因:構造体の比較
解決1:要素ごとの比較に変更。
解決2:演算子を定義。

3.2 error: invalid operands to binary expression ('ostream' (aka 'basic_ostream') and 'const std::__1::vector >')

c++のエラーについて @teratail 質問 freecss 回答 episteme
https://teratail.com/questions/67391

原因:「<<に対してconst vector適用」。operandが違う。
解決:「2か所」「const」追記。

3.3 invalid operands to binary expression ('double' and 'double')

浮動小数点の剰余計算をするための関数fmodf
http://memo755.blog.fc2.com/blog-entry-149.html

原因:「浮動小数で%演算子」
解決:fmodf関数を使用 うら紙のメモ hiiro

3.4 error: invalid operands to binary expression ('int' and 'void')

第27回 条件演算子のちょっと便利な使い方 Theoride Technology
https://theolizer.com/cpp-school2/cpp-school2-27/

原因:「int型とvoid型の足し算はない」
解決:型を合わせる

上記サイトに、?:の三項演算子の後ろにthrow, voidという話を、
コンパイルエラーのMSGから展開しているところが興味深い。
関連コンパイルエラーの一覧を作るときに、また参照したい。

3.5 : error: invalid operands to binary expression (std::_List_iterator and std::_List_iterator)

C++コンパイラ GCCとClangからのメッセージをお読みください
https://www.slideshare.net/digitalghost/bbk7

原因:listのbeginとendでsortできない。
解決:解説あり。最終的にどうしたか?

slideshareでコピペがし辛かった。再掲
###算譜(code)

err35.cpp
#include <list>
#include <algorithm>

int main(){
  std::list<int> l;
  std::sort(l.begin(), l.end());
}


編纂・実行結果(compile and go)

$ clang++ err35.cpp
/Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm:3898:40: error: invalid operands to binary expression ('std::__1::__list_iterator<int, void *>' and
      'std::__1::__list_iterator<int, void *>')
        difference_type __len = __last - __first;
                                ~~~~~~ ^ ~~~~~~~

この後、膨大に続く。

3.6 error: invalid operands to binary expression ('ostream' (aka 'basic_ostream') and 'std::pair')

C++N3242, 2011 (48) 6.6 Jump statements 6.6.3 The return statement"
https://researchmap.jp/jo68rg5gx-1797580/

原因:pairを出力する定義がない
解決:pair -> pair.first, pair.second 要素ごとの出力に変更

同一・類似事例

C++N4606, 2016 (61)6.6.3 The return statement [stmt.return]p149
https://qiita.com/kaizen_nagoya/items/09918f1f62f3ed8e308a

C++N4741 (69)9.6.3 The return statement [stmt.return]p136
https://qiita.com/kaizen_nagoya/items/fe8a8c2a3f6a77d00cb7

参考文献(reference)

C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010

C++N4606, 2016Working Draft 2016, ISO/IEC 14882,符号断片編纂一覧(example code compile list)
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

C++N3242, 2011 sample code compile list on clang++ and g++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318

Reference

Error一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.

文書履歴(document history)

ver. 0.10 初稿 20180522
ver. 0.02 URL追記 20230302

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3