Is there a way to create a class Foo
so that I can do:
Foo foo;
but not
Foo* foo = new Foo();
?
I don’t want people to be able to allocate copies of Foo on the heap.
Thanks!
EDIT: Sorry, I was wrong on the “stack only, not heap”. What I want to say is “can not use new operator”.
Make your
operator newprivate.On C++0x you can
deletetheoperator new:Note that you need to do the same for operator
new[]separately.