【问题标题】:Forward declaration of typedeftypedef 的前向声明
【发布时间】:2023-10-18 11:12:01
【问题描述】:

我有以下代码:

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;
    }
}

class JsonReader {

public:
    JsonReader();

    ~JsonReader() { };

    void processValuation(std::vector<Simulation> &simulations);

private:

    std::string processOptionParams(const ptree::value_type &node);

    void loadConfig(std::string filename);

    std::shared_ptr<boost::property_tree::ptree> jsonTree_;
};

一切都很好,但我不确定如何转发声明ptree::value_type。 有什么想法可以做到吗?

您可以在此处找到带有value_type 定义的文件 http://www.boost.org/doc/libs/1_60_0/boost/property_tree/ptree.hpp

【问题讨论】:

  • 您是否有特殊原因要转发声明它?

标签: c++ c++11 boost forward-declaration ptree


【解决方案1】:

您不能从前向声明的类型中前向声明类型成员。这让您要么从ptree 中提取value_type 的实际定义(不推荐),要么只包括​​完整的标题ptree.hpp

一旦您需要头文件中的类的内部结构,就不能选择前向声明。

【讨论】:

  • 好的,谢谢,我意识到我们不能转发声明类的“普通”成员,但我认为它可能与 typedef 不同。无论如何,非常感谢!