6 Years
Discussion Span
Last Post by Ancient Dragon

That can be done so the main() can "see" the class.
It's called scoping.
If the class is not in "scope" to a given piece of other code, it can't be directly used.


Class definitions are normally put in header files, which are included in the *.cpp file. This is done do that the class can be used anywhere within the program, not just main(). Right now you are probably writing very simple programs that contain only a main() function. What would you do with a program that has hundreds or even thousands of functions? You can't (or don't want to) define the same class over, and over for hundreds of times at the beginning of each function that needs it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.