3

我正在努力找出为什么带有以下代码段的代码无法编译。关于类模板可能有些我不理解的地方(即 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)错误是

'>'令牌之前的预期主表达式

如果我在该行替换Tint或其他内容,它仍然无法编译(“预期的主表达式之前int”)。

有什么想法吗?Boost::ptree 文档位于http://www.boost.org/doc/libs/release/boost/property_tree/ptree.hpp

4

1 回答 1

3

改变

return st.get<T>(name);

return st.template get<T>(name);

有关更多信息,请参阅此常见问题解答:什么是->template,.template::template语法?

于 2011-04-27T19:18:26.213 回答