如何从 pimpl 类调用调用者类的复制构造函数?
我只需要知道如果我想从 pImpl 类调用我的复制构造函数,我该怎么做? 例如:
CImpl::SomeFunc()
{
//cloning the caller class instance
caller = new Caller(*this)// I cant do this since its a pImpl class
}
我怎样才能实现这个目标?
I just need to know if I want to call my copyconstuctor from pImpl class, how will I do it?
For example:
CImpl::SomeFunc()
{
//cloning the caller class instance
caller = new Caller(*this)// I cant do this since its a pImpl class
}
How can i achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读您的评论后,您似乎希望能够提供复制
Caller
类的副本。如果是这样,那么在这种情况下,您应该为 Caller 类实现复制构造函数,您可以在其中制作m_pImpl
指针的硬拷贝。然后您可以在 CallerImpl 类中实现 Clone() 函数,如下所示:
现在您可以复制 Caller:
Well after reading your comments, it seems that you want to be able to provide the ability to make copies of
Caller
class. If so, then in that case you should implement the copy constructor forCaller
class, where you can make a hard copy ofm_pImpl
pointer.And then you can implement
Clone()
function inCallerImpl
class as:Now you can make copy of
Caller
: