Should I make this a singleton?

This is a discussion on Should I make this a singleton? within the C++ Programming forums, part of the General Programming Boards category; Hi, been a while since my last post. Been busy with a project.
Okay here's the question. I have an ...

Should I make this a singleton?

Hi, been a while since my last post. Been busy with a project.

Okay here's the question. I have an object that should only have an instance. But the object should not be created with the default constructor. It's because to create the object, the programmer should define the parameters of the creation of the object. I was thinking of doing this:

With this code, e.g., if I wanted to call method a, should call it with:

Code:

CObject::getInstance(param A, param B, param C, ...)->methodA();

But getting the instance with parameters that just only needed once to create the object is not too efficient so I was hesitant to implement it. I could just make it a generic one and just make sure I didn't make it more than once throughout my code. But I just wanted to see a different approach in this. Any idea?

With it still being a singleton, you can have a set parameters function to set the parameters. Then either create the object then or save them for when you need them. If you are creating the object then (because you know the program will always need it and there's no need to wait), then just make a Create function.

No, make a function that will initialize the object and create it with new. Then, make sure you call this function early in the program, before you try to use the singleton. Pass the user input to the function at that time, and that function calls the constructor with the data.

You could have the initialization variables saved in the class itself, but that would only make sense if you wanted to optimize it by not instantiating the class until it is needed.

Either way, the getInstance() method can just return the pointer, and if it hasn't been created then throw some sort of error. It won't need to take any parameters.

Basically, having getInstance() take parameters is a bad idea because this means that every place that wants to use the singleton either needs access to the original parameters or must create fake parameters and rely on the fact that, after first creating the object, getInstance simply discards them. This is unintuitive, inefficient and fragile.

Both approaches require the user of your class to set the parameters once (the first approach does this after creating the first instance). They also allows for those parameters to be reset by the user. The difference is that the second approach does this by destroying any existing object and creating a new one.