S
shaanxxx
how can we restrict object creation on heap ?
soln1: overload new
any other way to do this ?
soln1: overload new
any other way to do this ?
shaanxxx said:how can we restrict object creation on heap ?
soln1: overload new
any other way to do this ?
shaanxxx said:how can we restrict object creation on heap ?
soln1: overload new
any other way to do this ?
I think you mean require class instances to be in heap.
Wrong, unless I misunderstood above.
Easy, portable way: make all constructors
private, then provide a static member that
creates an instance on the stack, and
returns a pointer, like X::make_inst for
example:
static X * make_inst() { return(new X); }
I think you mean require class instances to be in heap.
Wrong, unless I misunderstood above.
Easy, portable way: make all constructors
private, then provide a static member that
creates an instance on the stack, and
returns a pointer, like X::make_inst for
example:
static X * make_inst() { return(new X); }
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.