请问 CDialog pDlg 与CDialog* pDlg=new CDialog有什么区别(谢谢)

xf_abc 2002-12-19 11:20:28
请问
CDialog* pDlg=new CDialog
pDlg->Create(...);
pDlg->ShowWindow(SW_SHOW)

CDialog pDlg;
pDlg.Create(...);
pDlg.ShowWindow(SH_SHOW)
有什么区别呢?
...全文
105 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
f_fire 2003-01-18
  • 打赏
  • 举报
回复
因为,后者可以进行动态改变指针所指向的对象,即对象是可以动态替换/改变的,所以,持很多种设计模式,用的似乎更多些。
用户 昵称 2003-01-17
  • 打赏
  • 举报
回复
it's instance and pointer
mcfdm 2003-01-17
  • 打赏
  • 举报
回复
up.
问题好像是很基础的哦。
saucer 2002-12-19
  • 打赏
  • 举报
回复
the first one creates the CDialog object on the heap, you need to call
delete pDlg;

to destroy the objec, otherwise the memory leaks

the second one creates the CDialog object on the stack, when the variable goes out of the scope, the object is destroyed

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧