boost::interprocess::ptree的前向声明
Foward declaration of boost::interprocess::ptree
我想为boost::property_tree
的ptree
类使用正向声明。
我使用Visual Studio 2010和增强版1.48.0。
我在我的.h 中以以下方式进行远期申报
#ifndef OPTIONS_H_
#define OPTIONS_H_
namespace boost
{
namespace property_tree
{
class ptree;
}
}
class Options
{
// something
private:
boost::property_tree::ptree *m_pxPropertyTree;
};
#endif // OPTIONS_H_
然后,我使用.cpp 中的类
#include <boost/property_tree/ptree.hpp>
using boost::property_tree::ptree;
Options::Options()
{
m_pxPropertyTree = new ptree();
// other stuff
}
当我试图编译它时,我得到了以下错误
错误C2371:"boost::property_tree::ptree":重新定义。不同的基础类型。c: \lib\boost\1.48.0\32\boost\property_tree\ptree_fwd.hpp 95
(错误描述可能会有所不同,我已经翻译了它,因为我有Visual Studio的意大利语版本)。
ptree_fwd.hpp中给出错误的行是以下
typedef basic_ptree<std::string, std::string> ptree;
相反,如果我不使用forward声明,那么一切都很顺利,并且我成功地编译了它。
我做错了什么,在这种情况下如何正确使用正向声明?
为什么不只包含boost/property_tree/ptree_fwd.hpp
?此标头包含包的所有转发声明。
编辑:不包含的解决方案(您希望避免有充分理由)是为了与实际声明的内容完全匹配。
因此:
#include <string>
#include <functional>
namespace boost
{
namespace property_tree
{
template < class Key, class Data, class KeyCompare >
class basic_ptree;
typedef basic_ptree< std::string, std::string, std::less<std::string> > ptree;
}
}
相关文章:
- .cpp和.h文件中的模板专用化声明
- 未在作用域中声明unordered_map
- C++避免重复声明的语法是什么
- 如何确保C++函数在定义之前声明(如override关键字)
- 错误:未在此范围内声明'reverse'
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 为什么在定义函数之前先声明它
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- #ifdef和未声明的标识符
- 没有显式声明的int[]中的foreach
- 在基于范围的for循环中使用结构化绑定声明
- 在将变量声明为引用时,堆在释放后使用
- C++:无法访问声明的受保护成员
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 在函数内部的声明中初始化数组,并在外部使用它
- Visual Studio中的函数声明和函数定义问题
- c++类声明时,相同的例程,不同的成员变量类型
- boost::interprocess::ptree的前向声明