I am writing small matrix library which uses Curiously recurring template pattern and i faced with following problem.
Have to classes Base
and Derived
. Derived has template parameter which denotes some scalar type. I want to create cast method inside Base which converts Derived-like class to Derived-like with another scalar.
Following code looks quite well but raises compile error in gcc 7.2.0
template<typename Derived>
class Base
{
public:
template<typename OtherT>
auto cast() const
{
return (static_cast<Derived*>(this))->cast<OtherT>();
}
};
template<typename T>
class Derived : public Base<Derived<T>>
{
public:
template<typename OtherT>
Derived<OtherT> cast() const
{
return Derived<OtherT>();
}
};
int main()
{
Derived<float> der;
return 0;
}
Error message:
a.cpp:14:51: error: expected primary-expression before ‘>’ token
return (static_cast<Derived*>(this))->cast<OtherT>();
^
a.cpp:14:53: error: expected primary-expression before ‘)’ token
return (static_cast<Derived*>(this))->cast<OtherT>();
But with gcc 6.4.0
everything is ok
Is there a way to fix it?
PS Sorry for my poor English.