Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 围绕boost::ptree的模板化类_C++_Templates_Gcc_Boost_Boost Propertytree - Fatal编程技术网

C++ 围绕boost::ptree的模板化类

C++ 围绕boost::ptree的模板化类,c++,templates,gcc,boost,boost-propertytree,C++,Templates,Gcc,Boost,Boost Propertytree,我正在努力找出为什么带有以下代码段的代码无法编译。关于类模板(例如typedef typename)可能有一些我不了解的地方,但我认为在这种特殊情况下,情况并非如此 template<typename data_type> class GlobalStore { private: typedef boost::property_tree::basic_ptree< std::string, data_type, std:

我正在努力找出为什么带有以下代码段的代码无法编译。关于类模板(例如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
    }
};
模板
类全球商店{
私人:
typedef boost::属性树::基本树<
std::字符串,
数据类型,
std::less
>_StorageTreeType;
_StorageTreeType_商店;
公众:
//剪断
模板
const T Get(_StorageTreeType&st,const std::string&name)
{
return st.get(name);//编译阻塞在这里
}
};
我使用了完全相同的设置,虽然在模板类之外(但仍然使用与上面所示完全相同的行)。编译器(GCC/MingW)错误为

应在
'>'
标记之前使用主表达式

如果我将
T
替换为
int
或该行中的某个内容,它仍然无法编译(“在
int
之前预期的主表达式”)

有什么想法吗?Boost::ptree文档正在更改

return st.get<T>(name);
返回st.get(名称);

返回st.template get(名称);

有关更多信息,请参阅此常见问题解答:

出色、简洁且切中要害。谢谢你的链接-我试着沿着这些线搜索,但从来没有发现。
return st.template get<T>(name);