我知道这可能被解释为那些“你更喜欢什么”的问题之一,但我真的想知道为什么你会选择以下其中一种方法。
假设您有一个超复杂类,例如:
class CDoSomthing {
public:
CDoSomthing::CDoSomthing(char *sUserName, char *sPassword)
{
//Do somthing...
}
CDoSomthing::~CDoSomthing()
{
//Do somthing...
}
};
我该如何在全局函数中声明一个局部实例?
int main(void)
{
CDoSomthing *pDoSomthing = new CDoSomthing("UserName", "Password");
//Do somthing...
delete pDoSomthing;
}
-- 或 --
int main(void)
{
CDoSomthing DoSomthing("UserName", "Password");
//Do somthing...
return 0;
}