0

I'm currently programming in c++ with class templates.
I would like to implement a class member function that calls a function in another class, which is given by the template argument.
However, the compiler gives error: expected primary-expression before ‘)’ token error.

Below it shows the simple reproduction of the situation. The sub class and its multiply method works well, but it doesn't for the sup class.
It does not make sense to me, as sub<3>::multiply<4>() and b::multiply<4>() works fine in the program.

Any idea?

#include <iostream>

template<int a>
struct sub {
    template<int b>
    static void multiply()
    {
        std::cout << a*b << std::endl;
    }
};

template<typename sub>
struct sup {
    template<int b>
    static void multiply()
    {
//        sub::multiply<b>(); // => "expected primary-expression before ‘)’ token"
    }
};

int main()
{
    sub<3>::multiply<4>();
    using b = sub<3>;
    b::multiply<4>();
    using p = sup<b>;
    p::multiply<4>();
}
cyl
  • 21
  • 2

0 Answers0