Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Placing Classes in Separate Files

+1 vote
asked Mar 25 by Farmanullah Hamat (130 points)
My professor at class made a separate file in codeBlock that she called it player and it automatically made two files for her that were named player.h and player.cpp. It had some info, but she describe it as that one of them is for writing classes and the other is for coding. I want to do that in onlineGDB, but I am not sure how? Is it the same way we create files, if so than do we have to type all the info that codeBlock created for my professor?

1 Answer

0 votes
answered Mar 27 by Peter Minarik (86,160 points)
In short, yes, you can create new files in OnlineGDB.There are two icons left of the green RUN button (right to left: upload a new file; create a new empty file). You can utilize these to add files to your OnlineGDB project.

To add a bit more detail, what you're talking about here is C++ header (.h) and source (.cpp) files. The header file is for declaration, i.e., to describe the functionality of the class, and specify the signature of the functions, list the fields the class has, list constants, specify macros, etc. in the file.

The source file is the definition of those in the header file, where you actually tell how the functions behave.

Also, it seems like CodeBlock had some auto-generated code. OnlineGDB doesn't seem to have this, but it's a good practice to learn writing classes from scratch to better understand how they are built up.

I hope this helps.

Have fun coding! :)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.