mardi 24 mai 2016

Singletons with constructor arguments

While trying do create a single instance of a class which will require global access and modification to it's name, I have some syntax related issue (I think) with my code in the implementation file.

When I compile, I get error on the return statement:

non-const lvalue reference to type Single cannot bind to a value of unrelated type Single.

single.h

class Single{
public:
   std::string getSingleName();
   void updateSingleName(std::string name);
   void operator=(Single const&) = delete;
   Single(Single const&) = delete;
   static Single& getInstance(const std::string& name);

private:
    Single(std::string singleName);  
    std::string name;
};

Single.cpp

Single& Single::getInstance(const std::string& name){
     Single single(std::string name);
     return single;
}

Aucun commentaire:

Enregistrer un commentaire