使用C ++ 17编译时无法从基类访问成员类型 [英] Can not access member type from base-class when compiled using c++17

查看:80
本文介绍了使用C ++ 17编译时无法从基类访问成员类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以在

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?

推荐答案

当基类 B 类取决于模板参数,即使派生类 D 在此处键入别名 AbcData B 继承而来,仅使用 D 类中的 AbcData ,还不够。

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
};

这篇关于使用C ++ 17编译时无法从基类访问成员类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆