命名空间编译问题 [英] Namespace compilation issues
问题描述
我是 Visual Studio 的新手(我使用的是 2005 版).我遇到了无法弄清楚的命名空间问题.
I am new to working in Visual Studio (am using version 2005). I am running into a problem with namespaces that I am not able to figure out.
我正在尝试创建一个静态库,稍后将链接到应用程序.
I am trying to create a static library which I will link to an Application later.
所以,我有一个包含以下代码的 XXX.h 文件
So, I have a XXX.h file with the following code
#ifndef _XXX_X_H
#define _XXX_X_H
namespace LLL_NWK
{
void lllInit();
}
#endif
我在 XXX.c 中包含了 XXX.h,代码如下
I include XXX.h in XXX.c and the code looks like
#include "XXX.h"
using namespace LLL_NWK;
void lllInit()
{
}
但是,当我构建库时遇到以下错误
However, when I build the Library I encounter the following errors
error C2061: syntax error : identifier 'LLL_NWK'
error C2059: syntax error : ';'
error C2449: found '{' at file scope (missing function header?)
error C2059: syntax error : '}'
我无法找出此错误的原因.希望得到一些帮助和指点.
I am unable to figure out the cause of this error. Would appreciate some help and pointers.
推荐答案
首先,using namespace LLL_NWK
在这里是不合适的.您正在声明和定义namespace LLL_NWK
的void lllInit()
outside 函数.您需要将定义放在命名空间内,可以这样做:
First, using namespace LLL_NWK
is not appropriate here. You are declaring and defining a function void lllInit()
outside of namespace LLL_NWK
. You need to place the definition inside of the namespace, which can be done like this:
void LLL_NWK::lllInit()
{
}
或者像这样:
namespace LLL_NWK
{
void lllInit()
{
}
}
其次,确保将代码编译为 C++.
这篇关于命名空间编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!