这是用例:
Log(char* s); // prints out a log message
Run Code Online (Sandbox Code Playgroud)
现在:
Log("hello world\n"); // called from Thread1
Run Code Online (Sandbox Code Playgroud)
期望的输出:
Thread1: hello world
Run Code Online (Sandbox Code Playgroud)
现在:
Log("hello world\n"); // called from Thread2
Run Code Online (Sandbox Code Playgroud)
期望的输出:
Thread2: hello world
Run Code Online (Sandbox Code Playgroud)
我可以有一个将线程pid映射到字符串的映射.然而,我需要的是一个函数,当调用不同的线程时,它给我唯一的识别标签.这可能吗?
谢谢!
(Langauge:C/C++)
如果是的话,该怎么办?
typedef struct Foo_struct{
Dog d;
Cat* c;
struct Foo_struct(Dog dog, Cat* cat){ this->d = dog; this->c = cat;}
} Foo;
Run Code Online (Sandbox Code Playgroud)
(背面故事:将用Visual C++(在Windows上)编写的程序移植到g ++(在MacOSX上);不知道这个代码是什么样的.
谢谢!
是否可以定义C++类Foo和Bar st
class Foo {
Bar makeBar();
};
class Bar {
Foo makeFoo();
};
Run Code Online (Sandbox Code Playgroud)
?
谢谢!
文档__thread
但我的 g++ 抱怨我的 arch(Macbookpro 上的 Leopard)不支持 __thread。
为什么是这样?我该如何解决它?
我正在寻找STL的一个变体(如果它没有所有的功能就没关系),它可以在短的编译时间内进行优化- 我会受到延迟编译调试编辑周期的长编译时间的困扰.
我主要对STL的容器感兴趣:vector/map,而不是算法.
谢谢!
在C中,我有格式字符串,如:
char *msg = "wlll you marry me"
fprintf(stderr, "%s, %s?", name, msg);
Run Code Online (Sandbox Code Playgroud)
现在,我可以使用格式字符串在lua中执行类似的操作吗?即我想要功能相当的东西:
name .. ", " .. msg .. "?"
Run Code Online (Sandbox Code Playgroud)
在卢阿,但不是那么难看.
好的,所以我可以做string.format("%s,%s?",name,msg),但是我可以更进一步,比如perl风格,我可以去哪里:
"%name, %msg?"
Run Code Online (Sandbox Code Playgroud)
谢谢!
想象一下,我在C-land,我有
void* my_alloc(size_t size);
void* my_free(void*);
Run Code Online (Sandbox Code Playgroud)
然后我可以浏览我的代码并用my_alloc/my_free替换所有对malloc/free的调用.
怎么,我知道给了一个Foo课,我可以做新的安置; 我也可以重载新运算符.但是,有没有办法为我的所有 C++类做到这一点?(即我想为新的和新的[]使用我自己的分配器;但我不想破解并破解我定义的每个类.)
谢谢!
我有一些代码使用:
__sync_bool_compare_and_swap
Run Code Online (Sandbox Code Playgroud)
它在Linux上编译得很好.
但是当我尝试在MacOSX上用g ++编译时,我得到:
error: ‘__sync_bool_compare_and_swap’ was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
我该如何解决?(这是Mac OSX 10.5.8,所以它的英特尔......应该有这个指令).
谢谢!
有没有办法定义模板
assertInheritsFrom<A, B>
Run Code Online (Sandbox Code Playgroud)
这样的
assertsInheritsFrom<A, B>
Run Code Online (Sandbox Code Playgroud)
编译当且仅当
class A : public B { ... } // struct A is okay too
Run Code Online (Sandbox Code Playgroud)
谢谢!
c++ ×7
assembly ×1
built-in ×1
c ×1
constructor ×1
containers ×1
g++ ×1
gcc ×1
inheritance ×1
lua ×1
new-operator ×1
pthreads ×1
shell ×1
stl ×1
templates ×1
visual-c++ ×1