Question

I'm struggling to find out why code with the following snippet will not compile. There may be something I don't understand about class templates (ie the typedef typename thing) but I don't think that's it in this particular case.

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

I have used the exact same setup, though outside of a templated class (but still using an exactly identical line to that shown above). The compiler (GCC/MingW) error is

expected primary expression before '>' token

If I replace T with int or something on that line it still won't compile ("expected primary expression before int").

Any thoughts? Boost::ptree documentation is at http://www.boost.org/doc/libs/release/boost/property_tree/ptree.hpp

Was it helpful?

Solution

Change

return st.get<T>(name);

to

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

See this FAQ for more info: What is the ->template, .template and ::template syntax about?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top