相关疑难解决方法(0)

如何防止在堆上创建对象?

有没有人知道我怎么能在平台无关的C++代码中阻止在堆上创建对象?也就是说,对于"Foo"类,我想阻止用户这样做:

Foo *ptr = new Foo;
Run Code Online (Sandbox Code Playgroud)

并且只允许他们这样做:

Foo myfooObject;
Run Code Online (Sandbox Code Playgroud)

有没有人有任何想法?

干杯,

c++ heap stack

26
推荐指数
3
解决办法
8478
查看次数

标签 统计

c++ ×1

heap ×1

stack ×1