0

I have the following code:

#include <boost/property_tree/ptree.hpp> 

class A { 
public: 
    const boost::property_tree::ptree & ptree() const { 
        return _pt; 
    } 
private: 
    boost::property_tree::ptree _pt; 
}; 

class B : public A { 
public: 
    int bla() const { 
        return ptree().get<int>("bla",0); 
    } 
}; 
template<class T> 
class C : public A { 
public: 
    int bla() const { 
        return ptree().get<int>("bla",0); 
    } 
}; 

So both classes B and C access the boost property tree inherited from A and call the templated method get("bla",0) on it. The only difference between B and C is the fact that C itself is a templated class. However for C I get the compiler error

test.cpp:22:31: error: expected unqualified-id before ‘>’ token 
         return ptree().get<int>("bla",0); 
                               ^

This is for GCC 4.8.3

It also works fine if B and C have their own property tree _ptree and do not access it via a call to A::ptree(). Is it a bug or do I miss something here.

Thank you very much indeed.

Oncaphillis
  • 1,888
  • 13
  • 15
  • 1
    `return ptree().template get("bla",0); ` – Piotr Skotnicki Dec 03 '14 at 19:01
  • @PiorS Thank you. That solves it but what is the compiler complaining about ? Why do I have to explicitly specify that it's a template ? With what could the compiler mix it up ? – Oncaphillis Dec 03 '14 at 19:06
  • 1
    @Oncaphillis see [Where and why do I have to put the “template” and “typename” keywords?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – Piotr Skotnicki Dec 03 '14 at 19:15

0 Answers0