#how to understand cpp compiler g++ error message.

15 messages · Page 1 of 1 (latest)

white vessel
#

I did java, then i did c, both have easy bug message, but that's not true for cpp.
Even if I do cin << instead of cin >> . This will produce error message so much, i can't understand the issue. I have to guess from line number.
Same today I forgot to initialise virtual function, it gave a weird message instead of simply telling me that.

Any why is that???

eager rampartBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

brave chasm
#

;compile cpp

#include <iostream>
int main() {
    std::cin>>2;
}
magic moatBOT
#
Compiler Output
<source>: In function 'int main()':
<source>:3:13: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'int')
    3 |     std::cin>>2;
      |     ~~~~~~~~^~~
      |          |    |
      |          |    int
      |          std::istream {aka std::basic_istream<char>}
In file included from /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/iostream:40,
                 from <source>:1:
/opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/istream:120:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  120 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/istream:120:7: note:   conversion of argument 1 would be ill-formed:
<sou
brave chasm
#

Start at the top

#
<source>: In function 'int main()':
<source>:3:13: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'int')
    3 |     std::cin>>2;
      |     ~~~~~~~~^~~
      |          |    |
      |          |    int
      |          std::istream {aka std::basic_istream<char>}
#

Always start at the top

#

This tells you where the problem is and the immediate reason why

#

same here

<source>: In function 'int main()':
<source>:3:13: error: no match for 'operator<<' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'int')
    3 |     std::cin<<2;
      |     ~~~~~~~~^~~
      |          |    |
      |          |    int
      |          std::istream {aka std::basic_istream<char>}
#

Compiler can't find a way to perform that operator

#

All the other lines, and there are a daunting number of errors yes, contain information about what the compiler tried and was unable to do

#

It goes through all the overload candidates and provides information about why each one does not apply here

eager rampartBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.