private
- static
( factory ), .
,
class MyClass{
private:
MyClass() = default;
public:
static MyClass* make() { return new MyClass; };
}
code:
auto mc = MyClass::make();
( new MyClass
)
... ( MyClass::make
) <memory>
header.
You can also define your own smart pointer class with their unary operator ->
and operator *
and your own divergent patterns , inspired by std::make_shared
...
just want the good old new and deleted
In genuine C ++ 11, this frowned and might be considered bad style. You should avoid using explicitly new
outside your library and use a smart pointer coding method.
source
share