tags:

views:

63

answers:

1

I am completely confused as to the proper way to layout a C++ project.

I had all my classes in separate .cpp files, with their definitions in .h files. I then had one "header.h" which contained all the class headers, external dependencies and a few other things. But I wasn't able to use class names in the header files, where I needed to declare a pointer to one.

Can someone please explain the proper object-orientated layout for a C++ project.

+3  A: 

You can fix the problem "wasn't able to use class names in the header files, where I needed to declare a pointer to one" by using forward class declarations, like:

class myClass;

However, having every class include a header.h that then includes every class is overkill. Instead, you should have each class specifically include only the classes and external dependencies that it actually needs.

Jon Rodriguez
Good point, although (not clear from the question), you could decide to have 1 external header to your module that could be included by dependent modules.
stefaanv
This is precisely what I was doing wrong, thanks for the quick answer. I'll accept soon if no-one comes up with a better answer.
Alexander Rafferty