Copy constructor called on singleton class

Viewed 1205

I have the following problem. I have a singleton with a getInstance member function that returns an instance. I call this somewhere in code and for some reason VC tries to call the copy constructor. Why is this? How do I fix this?

The header:

class FileSystemEntryCollection {
public:
    static FileSystemEntryCollection &getInstance();
private:
    FileSystemEntryCollection();
    FileSystemEntryCollection(FileSystemEntryCollection const&);
    void operator=(FileSystemEntryCollection const&);
}

Source file:

FileSystemEntryCollection &FileSystemEntryCollection::getInstance() {
    static FileSystemEntryCollection instance = FileSystemEntryCollection();
    return instance;
}

The following line calls the copy constructor:

auto collection = FileSystemEntryCollection::getInstance();

I've tried to leave in the relevant code, let me know if something else is needed.

3 Answers
Related