Keine brauchbare Konvertierung von std :: function nach bool
The C ++ 11std::function
soll @ implementieroperator bool() const
, warum sagt mir Clang, dass es keine brauchbare Konvertierung gibt?
#include <functional>
#include <cstdio>
inline double the_answer()
{ return 42.0; }
int main()
{
std::function<double()> f;
bool yes = (f = the_answer);
if (yes) printf("The answer is %.2f\n",f());
}
Der Kompilierungsfehler ist:
function_bool.cpp:12:7: error: no viable conversion from 'std::function<double ()>' to 'bool'
bool yes = (f = the_answer);
^ ~~~~~~~~~~~~~~~~
1 error generated.
BEARBEITE Ich habe das @ nicht gesehexplicit
Keyword .. keine implizite Konvertierung dann, ich denke, ich muss @ verwendstatic_cast
.