English 中文(简体)
如何组织 C+++ 项目[关闭]
原标题:How to organize a C++ project [closed]
Closed 11 years ago.

The community reviewed whether to reopen this question 2 years ago and left it closed:

更新这个问题, 以便用 < a href="/posts/10782554/edit>编辑此文章 来解答事实和引用。

我想知道在组织我的工程时, C++ 的最佳做法是什么。 我读到过, 我应该把所有源文件 (. cpp) 放在 src 文件夹和信头文件 (.h) 中, 应该放在包含文件夹中。 这是它应该的样子吗, 还是我应该把信头文件放到源文件文件夹中?

这是我的文件夹树结构

- Project
|
+--- src (.cpp)
|
+--- include (.h) ????
|
+--- test (cpp unit test)
|
+--- doc (docs)
问题回答

这是一个真正偏好的问题,但组织一个代码基础既有助于维护性,也便于理解代码。 人们应该尽可能多地采用模块方法。 你们的代码组织看起来几乎是正确的,我最好能:

- Project
|
+--- src (.cpp)
|
+--- include (.h) ????
|
+--- test (cpp unit test)
|
+--- doc (docs)
|
+--- bin (generated binaries)
|
+--- lib (external dependencies)

页眉文件 (.h) 应该放在包含文件夹中 。

不是全部。 只有公共域名中的人。 如果一个 class 或函数是模块所特有, 则该模块应包含该模块。 包含的文件夹应包含可以被其他模块包含的页眉 。

您可能还想加上:

  • bin - for keeping your libraries
  • lib - same
  • exe - generate executables here (optional, can be also in bin)
  • etc - configuration files




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签