例如:
code1.c/.cpp
int a;
// ... and so on
Run Code Online (Sandbox Code Playgroud)
code2.c/.cpp
int a;
int main(void) {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
去编译:
$gcc code1.c code2.c # this is fine
$
$g++ code1.cpp code2.cpp # this is dead
/tmp/ccLY66HQ.o:(.bss+0x0): multiple definition of `a'
/tmp/ccnIOmPC.o:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
C&C++之间是否存在全局变量链接差异?
可能重复:
如何使用整数等名称访问对象属性?
print_r($myObj) 给出以下结果:
stdClass Object
(
[4021450] => stdClass Object
(
[property1] => ooo
[property2] => xxx
)
[3971601] => stdClass Object
(
[property1] => 123
[property2] => 356
)
)
Run Code Online (Sandbox Code Playgroud)
如何使用大括号语法和变量来访问sub-object?
我试过了:
$myObj->'3971601'; // Parse error: syntax error
$myObj->{'3971601'}; // Works
$id = 3971601; $myObj->{$id}; // Notice: Trying to get property of non-object
$id = 3971601; $myObj->{''.$id}; // Notice: Trying to get property of non-object
$arr = (array)$myObj; $arr[3971601]; // Notice: Undefined offset: 3971601
$arr = …Run Code Online (Sandbox Code Playgroud)