2

Sometimes, you want to provide a class declaration, which is not merely an opaque forward declaration but has the public functionality exposed - yet you don't want to commit to your private, or implementation-specific, fields and methods. One solution for this is the pimpl idiom - using a pointer to an inner class, housing the implementation of the class exposed publicly.

I don't really like using pimpl and wish the language would allow you to have really-private members - so that code using the class does not 'see' their declaration (and thus probably doesn't need to be recompiled when the implementation details change). Also, recently, I've noticed C++ has been evolving much faster - a 3-year tick-tock pattern in standard updates. So... is there a proposal to add such functionality to C++? Do some compilers currently support it perhaps?

4

1 回答 1

1

是的,这样的提议是存在的。甚至还有几个以前的版本,最新的一个是去年的:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4173.pdf

该提案将允许operator.重载,列出几个用例:

  • 智能参考
  • 智能指针类似工作
  • 代理
  • 界面细化
  • 粉刺
  • 把手

您可以阅读链接的提案以获取更多信息。当然,这不一定会被接受,即使被接受,也可能不会进入 C++17。

于 2015-05-24T10:08:07.817 回答