相关疑难解决方法(0)

Meyers对Singleton模式线程的实现是否安全?

以下实现,使用延迟初始化Singleton(Meyers'Seingleton)线程安全吗?

static Singleton& instance()
{
     static Singleton s;
     return s;
}
Run Code Online (Sandbox Code Playgroud)

如果没有,为什么以及如何使其线程安全?

c++ multithreading design-patterns

129
推荐指数
5
解决办法
5万
查看次数

静态变量链接错误

我在mac上编写C++代码.编译时为什么会出现此错误?:

体系结构i386的未定义符号:"Log :: theString",引用自:libTest.a中的Log :: method(std :: string)(Log.o)ld:未找到体系结构i386 clang的符号:错误:链接器命令失败,退出代码为1(使用-v查看调用)

不确定我的代码是否错误或者我必须向Xcode添加其他标志.我当前的XCode配置是"静态库"项目的默认配置.

我的代码:

Log.h ------------

#include <iostream>
#include <string>

using namespace std;

class Log{
public:
    static void method(string arg);
private:
    static string theString ;
};
Run Code Online (Sandbox Code Playgroud)

Log.cpp ----

#include "Log.h"
#include <ostream>

void Log::method(string arg){
    theString = "hola";
    cout   << theString << endl; 
}
Run Code Online (Sandbox Code Playgroud)

我用测试代码调用'方法',这样:'Log :: method("asd"):'

谢谢你的帮助.

c++ xcode static-methods clang static-libraries

63
推荐指数
2
解决办法
3万
查看次数