0

Calling undefined function?

This may sound really stupid, but is there some way to reserve function call on loop and define that function later without changing anything in loop? Example what I want: while true { Call function, that is not defined yet. } Later: while true { call function; } calledFunction { cout<<"..."; } Sorry, if this is not clear, I am not native english speaker.

4th Nov 2016, 6:30 PM
Eťas Se Nudí
Eťas Se Nudí - avatar
2 Antworten
+ 2
Nothing you ask is stupid, no worries. We're all here to learn and help. I don't fully understand your question, but you can't dynamically add content to your code during runtime (define a function, like you want to do). If you want a function to only be called at a particular time, and not all the time, just use an if statement inside the loop. bool call = false; while (true) { if (call) { func(); break; } else call = true; } In this loop, the first iteration it will not call our function, as the if statement does not evaluate to true. On the second iteration, the function is called due to the if statement evaluating to true. We can then break after calling the function so we are not left in an infinite loop☺
4th Nov 2016, 7:30 PM
Cohen Creber
Cohen Creber - avatar
+ 1
Thanks a lot for first thing, that was what I wanted to know. :)
4th Nov 2016, 7:38 PM
Eťas Se Nudí
Eťas Se Nudí - avatar