Can not access member type from base-class when compiled using c++17 [duplicate]

老子叫甜甜 提交于 2020-08-17 05:38:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!