65,187
社区成员




class erp
{
HR* m_hr;
FI* m_fi;
public:
erp()
{
m_hr = new HR();
m_fi = new FI();
}
erp()
{
}
};
if "new FI()" failed in the constructor, how can you detect this problem and release the properly
allocated member pointer m_hr?
class erp
{
public:
erp()
: m_hr(new HR())
, m_fi(new FI())
{
}
~erp()
{
}
private:
auto_ptr<HR> m_hr;
auto_ptr<FI> m_fi;
};
也可以以这种形式
class A {...};
class B {...};
int main()
{
A * pA = new A;
B * pB = new B;
return 0;
}