0

how do i make only 1 object creation of any class?

5
  • You want to create one instance of a class? Commented Apr 4, 2010 at 1:23
  • to don't create it again. Or do you want to prevent that? ;) Commented Apr 4, 2010 at 1:24
  • 2
    You could use the singleton pattern, but this pattern is, a) very difficult to get right, b) almost always used unnecessarily. Why do you want to do this? Commented Apr 4, 2010 at 1:52
  • @Codenotguru: your question title is rather generic. You should edit your question and make it more specific. Commented Apr 4, 2010 at 3:56
  • Singleton pattern may become evil, there are many points that you should consider, on the surface it is the simplest pattern, but if you dig deeper it is dangerous. Commented Apr 5, 2010 at 9:03

2 Answers 2

1

It's known as the Singleton design pattern. There are many tutorials for it, e.g. one here.

Sign up to request clarification or add additional context in comments.

Comments

1

Check out the Singleton Pattern: http://sourcemaking.com/design_patterns/singleton

EDIT: Updated link from C# to C++

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.