访问私人成员 [英] Accessing private members

查看:102
本文介绍了访问私人成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过将类转换为void指针,然后转换为struct,访问类的私有成员是否合适?

Is it appropriate to access a class' private members by casting it to a void pointer and then to a struct?

我不认为我有权限修改包含我需要访问的数据成员的类。如果不道德,我不想冒间接访问数据成员的风险。

I don't think I have permissions to modify the class that contains the data members that I need to access. I don't want to take a risk accessing the data members in an indirect way if it is not ethical.

编辑:不得不进一步编辑...我是相当肯定的类不会被修改,所以这是确定的程度...我唯一的关注是,如果编码该类的人知道这一点,它可能不会跟他很好地:(。

Had to edit this further... I am pretty sure the class wouldn't be modified, so it's ok to that extent... my only concern is, if the person who coded that class gets to know of this, it might not go down well with him :(.

推荐答案

永远不要说永远不会我相信宇宙中的某个地方,有一种情况会迫使你必须这样做...

"Never say never". I'm sure somewhere in the universe, there's a situation that will force you to have to do this...

但是,如果我不得不这么做,我肯定会感到厌烦。你需要得到很多关于你的情况的意见,

But I certainly would cringe if I had to do it. You truly need get lots of opinions on your situation before pulling the trigger. Can you describe your specific situation and maybe we could see if it makes sense or what better alternatives might exist?

响应注释/问题 -
定义权限 - 如果有可能,机构许可这听起来不是一个编程问题,但是要谈论谁是主张所述许可的东西。也许这更多是一个政治问题,而不是一个技术问题?再次,我认为我们需要更多的细节 - 即使它在某种程度上是关于局势的政治。但是,这可能或可能不被视为超出了网站的范围。

In response to comment/question-- Define "permissions" -- institutional permission? That sounds like not a programming problem, but something to talk to whoever is asserting said permission. Maybe this is more of a political issue than a technical one? Again, I think we need more specifics--even if it was somewhat about the politics of the situation. That may or may not be deemed out of scope for the website, however.

这篇关于访问私人成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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