0

Does needing an input make it possible to define functions after the main function.

I saved a program made for shuffling a deck of cards so I could make sense of how classes work. What struck me about it was how many of the class members were written after the main function, which I thought couldn't be done. However, the program works. Is it because an integer input is needed that the compiler is able to read all the following codes after main while waiting for input? Otherwise, how is it possible?

25th Jan 2017, 4:30 PM
emily gilespie
emily gilespie - avatar
1 Resposta
+ 1
As long as the functions are declared in the class you can define them anywhere after the class and the compiler will find them, even if they come after main. It's the same with normal functions, if you declare them somewhere at the top of your program it doesn't matter where you define them. void myFunction(); // declaration int main() { myFunction(); } void myFunction(){} // definition
25th Jan 2017, 5:46 PM
Robobrine
Robobrine - avatar