如何同时访问私人和私人在类中声明的公共成员继承? [英] How to access both private & public member declared in class inherit?

查看:114
本文介绍了如何同时访问私人和私人在类中声明的公共成员继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个类树并继承了一个类bst树.
我想同时访问类tree.私有成员和公共成员,但出现以下错误:
无法访问在类Tree中声明的私有成员

请现在帮我!!!!!

i write a class tree and inherit a class bst tree.
i want to access both private and public member in class tree.but i have a following error:
cannot access private member declared in class Tree

please help me now!!!!!

推荐答案

错误非常明显:无法访问在类中声明的私有成员"

这就是为什么将它们声明为Private的原因,这样您就无法访问它们并弄乱类的内部.
如果确实需要,那么您需要与创建该类的任何人进行交谈,解释为什么它对您如此重要,然后进行更改.


或者找到另一种方法,这可能容易得多.
The error is pretty explicit: "cannot access private member declared in class"

That is why they are declared as Private - so that you can''t access them and mess up the internals of the class.
If you really need to, then you need to talk to whoever created the class, explain why it is so essential for you, and get it changed.


Or find another approach, which is probably a lot easier.


私有成员是私有的,因此继承的类无法访问它们.这是设计使然.受保护将可以从继承的类中进行访问,但在使用该类时则不能.

如果特定的类成员曾经是可见的,但现在已经隐藏了,则可以使用一种非常隐蔽和肮脏的方式.通过显式转换为仍可看到类成员的类型并从那里访问它的方式来工作.但这实际上不应该使用,因为它是错误的代码设计(显然).

祝你好运!
private members are private so inherited classes can''t access them. This is by design. Protected would make it possible to access from inherited classes but not when using the class.

There is a very sneaky and dirty way you could use if the specific class member was once visible but now hidden. This works by explicitly casting to the type where the class member was still visible and access it through there. But this shouldn''t actually be used because it is bad code design (obviously).

Good luck!


好.那么如何访问在类继承中声明的私有成员和公共成员?
Ok .So how to access both private & public member declared in class inherit?


这篇关于如何同时访问私人和私人在类中声明的公共成员继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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