Am I using files correctly?

closed account (Ey80oG1T)
So I have two files. One .cpp and one .h file.

The A.h file contains a class that has attributes and methods in it.

The B.cpp has #include "A.h" in it, it also is the "main" function, where everything will be taking place.

Is this everything I need? In my project, I have an empty .cpp file that has #include "A.h" in it. What is it for?
> I have an empty .cpp file that has #include "A.h" in it. What is it for?
Well I'm guessing it's called A.cpp

It's for the implementation of the class you have in A.h.

> The B.cpp has #include "A.h" in it, it also is the "main" function
Your B.cpp should ONLY be the main function, and other non member functions.

@OP,

@salem c is correct. Just to clarify one thing he said---don't interpret his post to say that the #include "A.h" line should be removed.

The #include "A.h" line is needed in this file if you plan to create an object or call a method declared in "A.h" in main().

I believe the statement was meant to say (in general terms) that you should not define main() as well as A:: methods in the same .cpp file.

Edit: removed code tags from around "main()" to avoid the compile and run icon.
Last edited on
it'll be easier to answer if you just post the files
Topic archived. No new replies allowed.