Horje
c++ pass argument to singleton Code Example
c++ pass argument to singleton
class Questionnary
{
  std::string _str;

  static Questionnary& getInstanceImpl(std::string* const s = nullptr)
  {
    static Questionnary instance{ s };
    return instance;
  }

  Questionnary(std::string* const s)
    : _str{ s ? move(*s) : std::string{} } // employ move ctor
  {
    if (nullptr == s)
      throw std::runtime_error{ "Questionnary not initialized" };
  }

public:
  static Questionnary& getInstance()
  {
    return getInstanceImpl();
  }
  static void init(std::string s) // enable moving in
  {
    getInstanceImpl(&s);
  }

  Questionnary(Questionnary const&) = delete;
  void operator=(Questionnary const&) = delete;
};




Cpp

Related
what is difference between single inverted and double inverted in programming languages Code Example what is difference between single inverted and double inverted in programming languages Code Example
how to get mouse position on window sfm; Code Example how to get mouse position on window sfm; Code Example
how to lock window resize c++ sfml' Code Example how to lock window resize c++ sfml' Code Example
what are specialized classes c++ Code Example what are specialized classes c++ Code Example
c++ get input without loop Code Example c++ get input without loop Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11