Yesterday I saw a question that was asking to prevent creating objects on heap.
After some thoughts, I came out the following:
class Foo
{
public:
Foo(const Foo& f) {}
static Foo getAnInstance()
{
return Foo();
}
private:
Foo() {}
};
But this can only guarantee the first object is on stack and it can’t go further because there is a public copy ctor.
I haven't seen the point of the question, but it's fun to think about; so my question: Is there a way to do so?