0

The following piece of code demonstrates the problem:

class Printer
{
public:
    template<int i = 2>
    void print() { cout << i; }
};

template<typename T>
class Base
{
protected:
    Printer printer;
};

template<typename T>
class Derived : public Base<T>
{
public:
    void foo()
    {
        this->printer.print<5>(); // the error happens here
    }
};

The error from GCC says "invalid operands of types (...) to binary ‘operator<’". For this reason I believe that it is a problem with parsing, I have tried using the template keyword, but to no avail so far.

When I use the default template parameter and call the function of the printer object in the following way, everything is fine.

this->printer.print();
AlexSee
  • 322
  • 3
  • 16
  • 4
    Show us how you tried to use `template`. Did you write it as `this->printer.template print<2>()`? – David G Mar 01 '14 at 17:30
  • Thanks 0x499602D2, this works. I saw the question Jarod42 mentions, but I must have missed it somehow. – AlexSee Mar 01 '14 at 17:36

0 Answers0