首页 > 试题广场 >

从概念上或语法上说,下面哪个不是正确使用auto_ptr的方

[问答题]
从概念上或语法上说,下面哪个不是正确使用auto_ptr的方法(假设已经包含了所需的头文件)?
auto_ptr<int> pia(new int[20]);
auto_ptr<string> (new string);
int rigue = 7;
auto_ptr<int>pr(&rigue);
auto_ptr db1 (new double);

推荐
auto_ptr<int> pia- new int[20];    // wrong, use with new, not new[]
auto_ptr<string> (new string);    // wrong, no name for pointer
int rigue = 7;
auto_ptr<int>pr(&rigue);             // wrong, memory not allocated by new
auto_ptr db1 (new double);        // wrong, omits <double>

发表于 2018-09-03 20:33:46 回复(0)