我想使用ptree
類boost::property_tree
的前向聲明。Foward聲明boost :: interprocess :: ptree
我使用Visual Studio 2010和boost版本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 \提升\ 1.48.0 \ 32 \提升\ property_tree \ ptree_fwd.hpp 95
(錯誤描述可以是不同的,我把它翻譯,因爲我的Visual Studio的意大利版)。
,讓我的錯誤,在ptree_fwd.hpp線,如下
typedef basic_ptree<std::string, std::string> ptree;
相反,如果我不使用前聲明,一切順利的話,我成功編譯它。
我在做什麼錯了,以及我在這種情況下如何正確使用前向聲明?
'ptree'不是類,但一個'typedef'(即另一種類型的別名)。這意味着當您嘗試轉發聲明時,您將其作爲類來執行,並且類和typedef將發生衝突。 – 2012-02-24 15:40:45
所以我必須轉發basic_ptree模板? – Jepessen 2012-02-24 15:52:36
@JoachimPileborg你爲什麼評論而不是回答? – 2012-02-24 15:55:10