当父元素和子元素对dat成员具有相同名称时,如何从子类访问父类的数据成员 [英] How to access parent class's data member from child class, when both parent and child have the same name for the dat member

查看:144
本文介绍了当父元素和子元素对dat成员具有相同名称时,如何从子类访问父类的数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的场景如下::

class Parent
{
public:
int x;
}

class Child:public Parent
{
int x; // Same name as Parent's "x".

void Func()
{
   this.x = Parent::x;  // HOW should I access Parents "x".  
}
}

此处如何从会员访问Parent的X儿童的功能。

Here how to access Parent's "X" from a member function of Child.

推荐答案

几乎得到它:

this->x = Parent::x;

是指针。

这篇关于当父元素和子元素对dat成员具有相同名称时,如何从子类访问父类的数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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