View Single Post
Join Date: Oct 2007
Posts: 15
Reputation: jaux is an unknown quantity at this point 
Solved Threads: 2
jaux's Avatar
jaux jaux is offline Offline
Newbie Poster

Is there a way to prevent creating objects on heap?

 
0
  #1
Dec 12th, 2007
Yesterday I saw a question that was asking to prevent creating objects on heap.

After some thoughts, I came out the following:

  1. class Foo
  2. {
  3. public:
  4. Foo(const Foo& f) {}
  5. static Foo getAnInstance()
  6. {
  7. return Foo();
  8. }
  9. private:
  10. Foo() {}
  11. };

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?
Reply With Quote