I'm implementing Singleton the way described in the first answer here. The getInstance() method returns a reference but what I'm not sure about is how I should create my new instance and check if it already exists before creating it and returning it.
class Song {
private:
Song song;
Song();
Song(Song const&); // don't implement
void operator = (Song const&); //don't implement
public:
static Song &getInstance();
}
So what should my getInstance();
implementation look like? I want to return the song member object if it already exists and otherwise create it and than return it. I know there's a n implementation in the link I added but I'm not sure it does what I want and I don't understand it very well.
Also, could someone explain what these two lines are for and why the =
operator is being overwritten?
Song(Song const&); // don't implement
void operator = (Song const&); //don't implement