问题
I have the following code which compiles successfully in c++14.
template<class T, class ...Args>
class B
{
public:
using AbcData = int;
};
template<typename ...Args>
class D : public B<float, Args...>
{
public:
AbcData m_abc;
};
But when compiled in c++17, it gives the following error.
error C2061: syntax error: identifier 'AbcData'
What is wrong with the code and how to fix this?
回答1:
When the base class B
class depends upon the template parameters, even though derived class D
here type alias AbcData
inherited from the B
, using simply AbcData
in D
class, is not enough.
You need to be explicit, from where you have it
template<typename ...Args>
class D : public B<float, Args...>
{
public:
typename B<float, Args...>::AbcData m_abc; // --> like this
};
来源:https://stackoverflow.com/questions/59640808/can-not-access-member-type-from-base-class-when-compiled-using-c17