include和forward声明都有错误
Error with both include and forward declaration
我正在开发一个使用ApacheXerces的大型代码库。我正在用clang++构建代码,但它给出了一个错误。
在一个特定的.h文件a.h
(a.cpp
的头(中,存在类Attributes的头文件的前向声明和包含,如下所示-
#include <xercesc/sax2/Attributes.hpp>
和
namespace XERCES_CPP_NAMESPACE{
class Attributes;
}
文件xercesc/sax2/Attributes.hpp
的代码为
XERCES_CPP_NAMESPACE_BEGIN
...<some code>...
class SAX2_EXPORT Attributes {
...<some code>...
}
...<some code>...
XERCES_CPP_NAMESPACE_END
使用clang构建代码时出现的错误是
a.cpp:45:39: error: member access into incomplete type 'const obixercesc_2_8::Attributes'
a.h:20:10: forward declaration of 'obixercesc_2_8::obixercesc_2_8::Attributes'
class Attributes;
这是来自a.pp的相应行,它引发了错误
void f(const XERCES_CPP_NAMESPACE::Attributes& attrs) {
/* this line ---> */ const XMLCh * pAppName = attrs.getValue(X("appName"));
但是,当我注释掉forward声明并在a.h中只包含Attributes标头时,这编译得非常好。当我使用g++而不是clang++时,代码也在构建中。
我不明白一些事情-
1( 当既有正向声明又有include时,为什么它不使用clang++构建
2( 为什么错误指向obixercesc_2_8::Attributes,而不是类Attributes的实际命名空间XERCES_CPP_NAMESPACE::Attributes
3( 为什么代码是用g++编译的?
这与其说是一个解决方案,不如说是一种假设,但无论如何,这里有一个想法。
出于某种原因,您在嵌套的命名空间obixercesc_2_8::obixercesc_2_8
中错误地正向声明了Attributes
,当您引用obixercesc_2_8::Attributes
时,CLang选择正向声明而不是Xerces的实现,因为它们不在同一个命名空间中(可能是因为using namespace
语句?(。从它的角度来看,有两个Attributes
声明,一个在obixercesc_2_8
中,一个是在obixercesc_2_8::obixercesc_2_8
中。CCD_ 11似乎是一个扩展到CCD_ 12的宏。
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 使用直接大括号初始化时,C++ 编译错误"声明末尾的预期";"
- 我的代码中有错误,未声明的标识符
- C++ LeetCode #377 的 DP 解决方案中,此代码是否有错误?
- C++ [错误] 声明'char '隐藏参数。什么意思?
- 试图建立银行管理系统,但有错误
- 我试图创建临时对象的方式有错误吗
- 我的随机生成器是否不工作,或者我决定人/骨架是否击中对手的方式是否有错误
- 我在OpenCV中有错误的"approxPolyDP(ROI_Vertices, ROI_Poly, 1.0, true)"
- 我在这个 C++ 代码上有错误吗?
- 是视觉C++优化器错误还是我的代码中有错误?
- 为什么一个简单的C++程序会有错误的结果?是 #define 引起的吗?
- 对此有错误
- C :数据文件有错误:预期的无限制ID
- 一个带有参数的程序,为什么此程序有错误的答案
- 仅使用boost.datetime在Windows上有错误
- 使用向量循环时,是否有错误
- Microsoft Visual Studio发现我所有的CUDA设备端函数都有错误
- 类中的静态函数给出了错误:声明中的两种或多个数据类型
- include和forward声明都有错误