我有以下代码段。
Home::Room::Room (param1, param2, param3) :
mem_1(param1),
mem_2(0),
mem_3(Office::Start(param1, param2, param3),
mem_4_cs("conn")
{
}
Office::Start(param1, param2, param3)
{
try
{
success something;
}
catch
{
// throw some exception.
// destroys the conn object "mem_4_cs" from class Home's member and create a new member object to be used in class Home
~DealWithObject(); // assume there is a destructor here that does it
DealWithObject(mem_4_cs); // Creates a new object with the new "conn" string as in class Home
}
}
我正在尝试销毁一个成员对象,该成员对象在进入临界区(mem_4_cs
)的同一个类(Office
)中,而不是创建它的那个(Home
)将一个新的返回到主页'类。有没有更好的方法来实现它?