复制构造函数 [英] Copy Constructors

查看:82
本文介绍了复制构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含指向系统资源的私有指针的类。我是

我非常肯定我需要有一个用户定义的拷贝构造函数来执行

深拷贝。有人可以把我放在正确的方向(即简化

材料或例子)吗?


-bryan


ps:需要注意的私有变量指向一个关键部分

信号量(用于同步访问对象)是动态的

在ctor /中分配/解除分配分别是dtor。我认为只需要一个浅的副本就会导致僵局。

i have a class that contains a private pointer to a system resource. i''m
quite sure that i will need to have a user defined copy-constructor to do a
deep copy. can someone put me in the right direction (that is, simplified
material or examples)?

-bryan

ps: the private variable that needs attention points to a critical section
semaphore (used to synch access to the object) that is dynamically
allocated/deallocated in ctor/dtor respectively. i believe that a mere
shallow copy will result in deadlock.

推荐答案

" Bryan Bullard" <第******************** @ sbcglobal.net>写道...
"Bryan Bullard" <th********************@sbcglobal.net> wrote...
我有一个包含指向系统资源的私有指针的类。我很确定我需要有一个用户定义的拷贝构造函数来做
深拷贝。谁能让我朝着正确的方向(即简化的材料或例子)?


Google for<<"of three of three C ++>> ;.


顺便说一下,你读的C ++书是什么并不能解释复制构造函数?

-bryan
ps:需要注意的私有变量指向一个关键部分
信号量(用于同步访问对象),它们分别在ctor / dtor中动态分配/解除分配。我认为仅仅是浅拷贝会导致死锁。
i have a class that contains a private pointer to a system resource. i''m
quite sure that i will need to have a user defined copy-constructor to do a deep copy. can someone put me in the right direction (that is, simplified
material or examples)?
Google for <<"the rule of three" C++>>.

BTW, what C++ book are you reading that doesn''t explain copy constructors?

-bryan

ps: the private variable that needs attention points to a critical section
semaphore (used to synch access to the object) that is dynamically
allocated/deallocated in ctor/dtor respectively. i believe that a mere
shallow copy will result in deadlock.




死锁,信号量,同步访问,关键部分,都是OT。

您可能希望发布到comp.programming.threads以获取更多信息。



Deadlocks, semaphores, synch access, critical sections, are all OT here.
You might want to post to comp.programming.threads for more information.




" Victor Bazarov" <五******** @ comAcast.net>在消息中写道

新闻:Ca7Wb.212414

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:Ca7Wb.212414


Rc4.1722383@attbi_s54 ...
Rc4.1722383@attbi_s54...
BTW,什么您正在阅读的C ++书中没有解释复制构造函数吗?
BTW, what C++ book are you reading that doesn''t explain copy constructors?




tc ++ pl。我正在寻找不同的观点或解释。



tc++pl. i''m looking for a different perspective or explanation.


这篇关于复制构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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