Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File/folder layout for a large C++ project with multiple levels of inheritance

Tags:

c++

c

inheritance

I'm in the planning stage of a relatively large (10k+ lines) project with several classes (30+) and several levels of class inheritance (5+).

What is the best (or most conventional) way to lay out my project in terms of file and folder structure?

  1. Should I have one file per class? Should I have one folder per inheritance branch?
  2. Should I have an 'include' folder that contains my header files, or should my header files be in the same folder as my .cpp/.c files?
  3. I plan on regularly adding more classes (adding more levels to the inheritance tree). At the lowest level in the tree, implementations are likely to be relatively unrelated but still override the same virtual functions. Should such unrelated implementations reside in the same folder?

Thanks,
Advait

like image 613
advait Avatar asked Feb 27 '23 15:02

advait


1 Answers

1) Yes. One file per class in most cases is a good idea. Unless you have a really trivial class, or a collection of abstract interfaces, use one class per file.

2) Try to separate things. Usually in a project that big, you'll have some code that are specific to some parts, others that are common to many parts. Those that are very limited in usage, just keep it 'locally'. Others, put is in include dirs.

3) No need really. It is usually better to keep classes (i.e. files) which are closely related, close together; I'd try to keep them together, unless you have something like a generic interface, in your global includes, and specific inheritance inside a module dir.

like image 180
Gianni Avatar answered May 03 '23 20:05

Gianni