Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

c++ - What causes std::bad_function_call?

I've seen a few questions that refer to the std::bad_function_call exception, but haven't been able to find out any by Googling about what causes this exception.

What kind of behavior is supposed to cause this exception? Can you give me minimal examples that don't have other semantic problems also going on?

question from:https://stackoverflow.com/questions/5567287/what-causes-stdbad-function-call

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Sure- the easiest is where you try to call a std::function that's empty.

int main() {
    std::function<int()> intfunc;
    int x = intfunc(); // BAD
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...