Templated class around boost::ptree headache
-
24-10-2019 - |
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
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?