例如,假设我有一个 Game 类:
class Game{
public:
Game();
~Game();
void CreateWindowClass(HINSTANCE);
void CreateRessources(HINSTANCE);
void ShowMainScreen();
Winsock* CreateWinsock();
MessageLog* CreateMessageLog();
D2DResources* CreateD2DResources(HWND);
HWND Getm_hWnd();
public:
D2DResources* pD2DResources;
Winsock* pWinsock;
MessageLog* pMessageLog;
private:
HWND m_hWnd;
};
Game 中的 3 个指针是这样分配的:
Winsock* Game::CreateWinsock()
{
pWinsock = new Winsock;
return pWinsock;
}
这会导致任何问题吗?另外,我是否会像这样删除动态创建的对象:delete pWinsock;?