Sign in to follow this  

c++ A header/cpp for each class or not?

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

WinMain can be defined in the same module (.cpp file) as your main class. You can have a seperate main.cpp or entry.cpp, too but from my experience WinMain is very short and needs the defintion of your main class anyway. So I don't see any advantage of having it in a seperate file.

[edit]Typos - I'd better get some sleep [wink][/edit]

Pat.

Share this post


Link to post
Share on other sites
what I tend to do is put all the class headers in one header (ClassDef.h) and then put all the function definitions in seperate files (aka, font.cpp, render.cpp, coolgfx.cpp), that way I can easily open one file, and look up the functions for the classes, without searching for the right file.

Share this post


Link to post
Share on other sites
Quote:
Original post by Virus2566
what I tend to do is put all the class headers in one header (ClassDef.h) and then put all the function definitions in seperate files (aka, font.cpp, render.cpp, coolgfx.cpp), that way I can easily open one file, and look up the functions for the classes, without searching for the right file.


But if you change anything in the header you have to recompile every cpp file

Share this post


Link to post
Share on other sites
I prefer the .cpp/.h combination, however, I don't bother with a header file for main.cpp, and if a class is very small, or a pure virtual class I don't make a .cpp for it.
This is mainly to keep compile time down to an absolute minimum, but in the end it boils down to personal preference, there is no 'Right way' to store c++ code.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
in the end it boils down to personal preference, there is no 'Right way' to store c++ code.


Personal preference isn't the bottom line when you're working with a team or coming to an existing project.

Industry practice is to seperate into .cpp and .h for each class. That would be the most common approach.

Share this post


Link to post
Share on other sites

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this