【发布时间】:2014-05-28 00:45:28
【问题描述】:
我有一个用 C 编写的 .inc 文件。其中包含一些定义和方法签名及其实现。
.inc 文件:
#define CONCAT(x,y) x ## y
#define LCONCAT(x,y) CONCAT(x,y)
#define DLIST LCONCAT(LCONCAT(double_,LISTELEMENT),_list)
#define DELETEDFIRST LCONCAT(delete_first_double_,LISTELEMENT)
int DELETEDFIRST (DLIST **first, DLIST **last);
int DELETEDFIRST (DLIST **first, DLIST **last)
{...}
我想把它带到 C++ 中。在我的 .h 文件中,我有定义指令和方法签名(封装在命名空间中)。在 .cpp 中我只有方法实现。
.h 文件
#define CONCAT(x,y) x ## y
#define LCONCAT(x,y) CONCAT(x,y)
#define DLIST LCONCAT(LCONCAT(double_,LISTELEMENT),_list)
#define DELETEDFIRST LCONCAT(delete_first_double_,LISTELEMENT)
namespace ListFunctions {
int DELETEDFIRST (DLIST **first, DLIST **last);
}
.cpp 文件
# include ListFunctions.h
namespace ListFunctions {
int DELETEDFIRST (DLIST **first, DLIST **last) {...}
}
我计划在我的模块开发中使用这些列表函数。在我的 module.h 中,我定义了一个类型 double_node_list(双端),在我的 module.cpp 中,我将 LISTELEMENT 定义为“node em>”,然后包含 ListFunctions.h。但是 ListFunctions.cpp 中的相同包含会导致编译错误:
..\ListFunctions.h(86): error C2065:'double_LISTELEMENT_list' : undeclared identifier
..\ListFunctions.h(86): error C2065: 'first' : undeclared identifier
..\ListFunctions.h(86): error C2065: 'double_LISTELEMENT_list' : undeclared identifier
..\ListFunctions.h(86): error C2065: 'last' : undeclared identifier
..\ListFunctions.h(86): error C2078: too many initializers
稍后我想将 c 风格的实现翻译成 c++。由于我缺乏经验,我想知道其他人是否同意我的做法。
【问题讨论】:
-
错误:..\ListFunctions.h(86):错误 C2065:'double_LISTELEMENT_list':未声明的标识符 ...\ListFunctions.h(86):错误 C2065:'first':未声明的标识符。 ..\ListFunctions.h(86):错误 C2065:'double_LISTELEMENT_list':未声明的标识符 ...\ListFunctions.h(86):错误 C2065:'last':未声明的标识符 ...\ListFunctions.h(86):错误 C2078:初始化程序太多
-
LISTELEMENT 未知。即使我在 ListFunctions.cpp 中将其定义为“节点”,“double_node_list”仍然是一个未声明的标识符。我在我的模块中包含 ListFunctions.h 两次,在 ListFunctions.cpp 中包含一次