单独的“包括”和“src”应用程序级代码的文件夹? [英] Separate "include" and "src" folders for application-level code?

查看:185
本文介绍了单独的“包括”和“src”应用程序级代码的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题大多关注Unix / Linux风格的C ++开发。我看到许多C ++ 将其头文件存储在include文件夹中,将源文件存储在src文件夹中。为了一致,我在我自己的代码中采用了这一点。但是我不清楚这是否应该为应用程序代码。我看到了一些使用平面目录结构的情况。建议的方法是什么?

This questions concerns mostly Unix/Linux style C++ development. I see that many C++ libraries store their header files in a "include" folder and source files in an "src" folder. For the sake of conformance I adopted this in my own code. But it is not clear to me whether this should be done for application code as well. I've seen a few cases where a flat directory structure is used for that. What would be the recommended approach?

推荐答案

我也分开了他们,但不是严格的扩展,文件。

I also separate them, but not strictly on the extension, but on the access of the file.

假设您有一个管理客户信息的模块,并使用两个类来完成此操作:Customer,CustomerValidityChecker。
还假设应用程序中的其他部分只需要了解Customer类,CustomerValidityChecker只能由Customer类使用来执行一些检查。
基于这些假设,我存储这样的文件:

Suppose you have a module that manages customer information and uses 2 classes to do this: Customer, CustomerValidityChecker. Also suppose that other parts in your application only need to know about the Customer class, and that the CustomerValidityChecker is only used by the Customer class to perform some checking. Based on these assumptions I store the files like this:

公用文件夹(或include文件夹):

Public folder (or include folder):


  • customer.h

私人文件夹(或源文件夹):

Private folder (or source folder):


  • customer.cpp

  • customervaliditychecker.h

  • customervaliditychecker.cpp

这样,您的模块的调用者就可以立即清楚哪些部分可访问(公共),哪些部分不可访问。

That way, it becomes immediately clear for callers of your module which parts are accessible (public) and which parts aren't.

这篇关于单独的“包括”和“src”应用程序级代码的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆