【发布时间】:2014-07-12 10:39:40
【问题描述】:
在 C# 中,将所有类放入一个唯一的命名空间很简单。我了解命名空间在 C++ 中的工作原理很简单。但是当将许多文件放在一起以显示为一个命名空间时,我真的很困惑。 可能是这样的:
/* NetTools.cpp
blade 7/12/2014 */
using namespace std;
using namespace NetTools;
#include "NetTools.h"
int main()
{
cout << "testing" << endl;
return 0;
}
//####### EOF
/* NetTools.h
blade 12/7/2014 */
#ifndef NETTOOLS_H
#define NETTOOLS_H
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
namespace NetTools
{
}
#endif
// #### EOF
/* Commands.h
blade 7/12/2014 */
#include "NetTools.h"
#ifndef COMMANDS_H
#define COMMANDS_H
namespace NetTools
{
}
#endif
// ###### EOF
我将其 .h 文件中的每个类声明和其 cpp 文件中的实现分开,但我希望所有内容都在同一个命名空间中。
【问题讨论】:
-
如果您将出现在不同头文件中的声明放入同一个命名空间,它们将共享它。我不明白你的实际问题是什么。还要注意,你应该在你的包含守卫中包含东西,而不是在外面。
标签: c++ c++11 namespaces preprocessor-directive