jeudi 15 février 2018

An error related to assignment within an if-statement condition

What could be wrong with this construct?

    if((auto idx = diff * 2) <= objRef.size()){


          //do something
}

where diff is of type ptrdiff_t and objRef is of type std::vector.

The following compiler errors are generated for the above statement:

   1 In file included from main.cpp:1:
   2 ./bt.hpp:597:28: error: expected ')'
   3                   i
   4                   if((auto idx = diff * 2) <= objRef.size())
   5 f((auto idx = diff * 2) <= objRef.size())
   6                            ^
   7 ./bt.hpp:597:22: note: to match this '('
   8                   if((auto idx = diff * 2) <= objRef.size())
   9                      ^
  10 ./bt.hpp:597:44: error: expected expression
  11                   if((auto idx = diff * 2) <= objRef.size())
  12                                            ^

Aucun commentaire:

Enregistrer un commentaire