src/C ++中的文件夹结构? [英] src/ folder structure in C++?

查看:209
本文介绍了src/C ++中的文件夹结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Java/AS3-land进入C ++,并且我习惯了类的package-cum-folder结构.我喜欢它.

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.

我了解c ++中名称空间的基础知识,并且很高兴将其保留为基础知识.但是,随着我的项目变得越来越复杂,我想以一种可以让我牢牢记住的方式来组织我的文件夹结构.即类似于Java/AS3.

i understand the very basics of namespaces in c++, and i'm happy to leave it at just the basics. but, as my project gets more complex, i'd like to keep my folder structure organized in a way i can keep in my head. i.e. something similar to Java/AS3.

1)有什么理由具有以下文件夹结构:

1) is there any reason to not have a folder structure like:

src/
 model/
 view/
 controller/

可能带有子文件夹? (这只是一个MVC示例,文件夹结构可以根据项目的需要而定.)在其中包含大量头文件和源文件的src/文件夹似乎是不守规矩的.

possibly with subfolders? (this is just an MVC example, the folder structure could be whatever depending on the project's needs.) it just seems unruly to have a src/ folder with a huge pile of header and source files within.

2)如果对1)的回答可能是继续做您想做的事",是否为每个文件夹创建一个名称空间是不明智/不必要的,类似于Java/AS3为每个文件夹创建包的方式?我的理解是,名称空间通常不像这样使用,而是嵌套得很深并且与文件夹相关.

2) if the answer to 1) could be "go ahead and do what you want", would it be unwise/unnecessary to create a namespace for each folder, similar to Java/AS3's way of creating a package for each folder? my understanding is that namespaces are not usually used like this, nested deeply and folder-related.

推荐答案

我一直喜欢每个文件夹的名称空间.通常是因为当我不得不维护别人的代码时,命名空间可以帮助我找到最初定义类的位置.

I've always liked the namespace for each folder. Mostly because when I have to maintain somebody else's code, the namespace helps me find where the class was originally defined.

虽然命名的头文件也可以提供帮助.我也不建议使用超过2-3个名称空间,因为那样只会令人讨厌.您会发现自己使用使用名称空间等等";很多我总是发现C ++代码是一个危险信号.而且,在没有发生一些严重问题的情况下,您不能在头文件中使用使用命名空间".

Well named header files can also help with this though. I also wouldn't suggest going more than 2-3 namespaces, as then it just becomes obnoxious. You'll find yourself using "using namespace blah;" a lot which I always find to be a red flag for C++ code. And you can't use "using namespace" inside a header file without some severe problems occurring.

尽管在C ++中,这完全是可选的.

It's all completely optional though in C++.

这篇关于src/C ++中的文件夹结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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