IP_ADAPTER_INFO *ptr=new IP_ADAPTER_INFO[100];
Run Code Online (Sandbox Code Playgroud)
如果我免费使用
delete ptr;
Run Code Online (Sandbox Code Playgroud)
它会导致内存泄漏,如果不是那么为什么?
这是VS2005生成的反汇编代码
; delete ptr;
0041351D mov eax,dword ptr [ptr]
00413520 mov dword ptr [ebp-0ECh],eax
00413526 mov ecx,dword ptr [ebp-0ECh]
0041352C push ecx
0041352D call operator delete (4111DBh)
00413532 add esp,4
; delete []ptr;
00413535 mov eax,dword ptr [ptr]
00413538 mov dword ptr [ebp-0E0h],eax
0041353E mov ecx,dword ptr [ebp-0E0h]
00413544 push ecx
00413545 call operator delete[] (4111E5h)
0041354A add esp,4
Run Code Online (Sandbox Code Playgroud) 假设类stringGetter只包含一个纯虚函数:重载的运算符,字符串运算符()(int x).还假设类getPageString是一个实现operator()的公共stringGetter.
以下哪个C++语句肯定会导致编译器错误?
(a) stringGetter * a = new stringGetter;
(b) stringGetter * a = new getPageString;
(c) stringGetter * a;
getPageString * b = new getPageString;
a=b
(d) Exactly two of these will result in a compiler error.
(e) It is possible that none of these will result in a compiler error.
Run Code Online (Sandbox Code Playgroud)
我对抽象基类有点模糊,我无法在网上找到像下面那样进行分配的好例子.我喜欢在这里询问关于这类东西的问题,因为我经常学到更多关于我甚至不打算学习的东西.我甚至无法猜测这些会导致编译器错误.任何人都可以通过交流,告诉我为什么或为什么不会导致编译错误?