隐藏私人数据成员? (C ++) [英] Hiding private data members? (C++)

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

问题描述

有没有办法隐藏C ++类的私人数据成员远离其用户,在cpp文件?

Is there a way to hide private data members of a C++ class away from its users, in the cpp file? I think of the private members as part of the implementation and it seems a little backwards to declare them in the header file.

推荐答案

我们将私有成员作为实现的一部分,看起来有点落后。

The "pimpl" idiom is how this is generally handled.

请参阅

  • http://www.gotw.ca/gotw/024.htm
  • http://www.gotw.ca/gotw/028.htm
  • http://herbsutter.com/gotw/_100/ (updated for C++11)

这篇关于隐藏私人数据成员? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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