'Derived template member functions cannot be converted to template member functions of the base class error
Code works on (GCC5, c++14, ubuntu16) but doesn't work on (GCC7, c++14 ubuntu18) .
Could anyone can help ?
/workspace/c++/test/test/test.cpp:233:51: error: expected primary-expression before '>' token OtherT s = d->cast.template d->cast<OtherT>() ;
/workspace/c++/test/test/test.cpp:233:53: error: expected primary-expression before ')' token OtherT s = d->cast.template d->cast<OtherT>() ;
#include<iostream>
template<typename T>
class Base
{
public:
template<typename OtherT>
OtherT cast() const
{
OtherT a;
T b;
std::cout << "base" << std::endl;
return a;
}
};
template<typename T>
class Derived : public Base<T>
{
public:
template<typename OtherT>
OtherT cast() const
{
// using base = Base<T>;
// using base::cast<OtherT>;
auto d = (static_cast<Base<T>* >(this));
OtherT s = d->cast.template d->cast<OtherT>() ;
return s;
// return d.template Base<T>::cast<OtherT>();
}
};
int main()
{
Derived<float> der;
return 0;
}
Solution 1:[1]
cast is a template function, so you need to explicitly specify the template keyword
OtherT s = d-> template cast<OtherT>();
// ^^^^^^^^
Also, you don't need d->cast.template d, d is already Base<T>*.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
