C ++继承的类具有相同名称的成员 [英] C++ inherited class has member of same name

查看:96
本文介绍了C ++继承的类具有相同名称的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,您可以将成员放在基类中,而将相同名称的成员放在继承的类中.

In C++ you can put a member in a base class and a member with the same name in the inherited class.

如何访问继承的类中的特定类?

How can I access a specific one in the inherited class?

推荐答案

在这种情况下,您应该完全限定成员名称.

In that case you should fully qualify a member name.

class A
{
public:
  int x;
};


class B : public A
{
public:
  int x;
  B() 
  { 
    x = 0;
    A::x = 1;
  }
};

这篇关于C ++继承的类具有相同名称的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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