src/ folder structure in C++?

前端 未结 6 1081
离开以前
离开以前 2021-02-02 00:01

i\'m coming into C++ from Java/AS3-land, and i\'m used to the package-cum-folder structure for my classes. and i like it.

i understand the very basics of namespaces in

6条回答
  •  情话喂你
    2021-02-02 00:34

    You may want to have a look at John Lakos Large-Scale C++ Software Design. Basically, you can do that, but your packages should (as in Java) have an acyclic dependency graph. Also, it may be opportune for each package to document which headers are exported and which aren't, maybe like so:

    src/
     |- package1/
         |- exported_symbols_1.hh
         |- exported_symbols_2.hh
         |- src/
             |- impl_1.hh
             |- impl_1.cc
     |- package2/
         |- sub_package_2_1/
             |-  exported.hh
             |-  src/
                     ...
          |- src/
                ...
    

    Each package is only allowed to #include the top-level headers of another package, never ones in src/ directories.

    Also, when you want to use Autotools in a large project and intend to distribute headers, it may prove to be prudent to call the top-level directory not src/ but by the PACKAGE_TARNAME of that project. This makes installing headers with the help of the Autotools easier.

    (And, of course, the actual file names do not look as silly as illustrated above.)

提交回复
热议问题