围绕boost::ptree头疼的模板化类

Templated class around boost::ptree headache

本文关键字:boost ptree 围绕      更新时间:2023-10-16

我正在努力找出为什么使用以下代码片段的代码无法编译。可能有一些我不理解的类模板(即typedef typename的东西),但我不认为这是它在这个特殊的情况下。

template<typename data_type>
class GlobalStore {
private:
    typedef boost::property_tree::basic_ptree<
        std::string,
        data_type,
        std::less<std::string>
    > _StorageTreeType;
    _StorageTreeType _store;
public:
    // snip
    template<typename T>
    const T Get(_StorageTreeType & st, const std::string & name)
    {
        return st.get<T>(name);  //Compilation chokes here
    }
};

我使用了完全相同的设置,尽管是在模板化类之外(但仍然使用与上面所示完全相同的行)。编译器(GCC/MingW)错误是

'>'标记前期望的主表达式

如果我将T替换为int或该行上的其他内容,它仍然不会编译("int之前的预期主表达式")。

任何想法吗?Boost::ptree文档在http://www.boost.org/doc/libs/release/boost/property_tree/ptree.hpp

变化

return st.get<T>(name);

return st.template get<T>(name);
关于->template, .template::template的语法是关于什么的?