何时使用*(新Foo)

时间:2017-10-22 06:12:53

标签: c++ dynamic heap new-operator

所以我读到了像

这样的问题
ALTER TABLE `MY_TABLE`
PARTITION BY RANGE COLUMNS (`start_time`)
(
  PARTITION `p2012` VALUES LESS THAN ('2012-01-01 00:00:00'),
  PARTITION `p2013` VALUES LESS THAN ('2013-01-01 00:00:00'), 
  PARTITION `p2014` VALUES LESS THAN ('2014-01-01 00:00:00'), 
  PARTITION `p2015` VALUES LESS THAN ('2015-01-01 00:00:00'), 
  PARTITION `p2016` VALUES LESS THAN ('2016-01-01 00:00:00'),
  PARTITION `p2017` VALUES LESS THAN ('2017-01-01 00:00:00'), 
  PARTITION `pfuture` VALUES LESS THAN (MAXVALUE)
);

因为在Foo bar = *(new Foo()); 超出范围并从堆栈中删除后,无法从堆中清除bar。它有什么实际用途吗?

1 个答案:

答案 0 :(得分:2)

Foo& foo = *(new Foo);
delete &foo;

但不要这样做。这将使未来的维护者感到困惑,并且没有充分的理由。使用指针。