我试图在使用单例实例的不同线程上运行print()和print(char ch)方法.
错误C3867:'Singleton :: print':函数调用缺少参数列表; 使用'&Singleton :: print'创建指向成员的指针
错误C3867:'Singleton :: print':函数调用缺少参数列表; 使用'&Singleton :: print'创建指向成员的指针
错误C2661:'std :: thread :: thread':没有重载函数需要2个参数
class Singleton
{
private:
Singleton()
{}
static Singleton* singletonInstance;
public:
static Singleton* getSingletonInstance();
void print()
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
for (int i = 0; i < 100000; i++)
{
cout<<i<<endl;
}
}
void print(char ch)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
for (int i = 0; i < 100000; i++)
{
cout<<ch<<" "<<i<<endl;
}
}
};
Singleton* Singleton::singletonInstance = nullptr;
Singleton* Singleton::getSingletonInstance()
{
if(!singletonInstance) …Run Code Online (Sandbox Code Playgroud)