Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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;
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: unreal get eobjecttypequery cpp´ 
Cpp :: logisch und 
Cpp :: cv2.threshold c++ 
Cpp :: C++ Area of Scalene Triangle 
Cpp :: c++ get input without loop 
Cpp :: retourner pointeur de type qstringlist qt 
Cpp :: std string to wstring 
Cpp :: c++ make constructor fails if bad argument 
Cpp :: cpp iterate words from string 
Cpp :: c++ vector combine two vectors 
Cpp :: climits in cpp 
Cpp :: c++ default array value not null 
Cpp :: call of overloaded ‘swap(int&, int&)’ is ambiguous 
Cpp :: c++ uniform_real_distribution get same result 
Cpp :: c++ std::find with lambda 
Cpp :: casting pointer (int to char*) in c++ 
Cpp :: c++ std::copy to cout 
Cpp :: c++ print current time 
Cpp :: function as argument in another function in c++ 
Cpp :: how to print fixed places after decimal point in c++ 
Cpp :: tarray ue4 c++ 
Cpp :: tic toc toe c++ 
Cpp :: optimized bubble sort 
Cpp :: c++ declaring and initializing strings 
Cpp :: how to copy one vector to another 
Cpp :: C++ switch - case - break 
Cpp :: sin in c++ 
Cpp :: matplotlib hide numbers on axis 
Cpp :: convert binary string to int c++ 
Cpp :: memset in c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =