我想返回一个类的当前对象。由于 $this 变量指的是该类的当前对象,但是当我返回 this 时,我收到一个错误。
这是我的代码
class Test{
$name;
public static function getobj($n){
$this->name; return $this;
}
}
$obj= Test::getobj("doc");
Run Code Online (Sandbox Code Playgroud) 我有一个这样的嵌套循环结构:
for(int i =0; i<3; i++ ){
for(int j=0; j<4; j++)
{
if( ar[i][j]==0){
flag=true; continue;
}else{
flag=false; break;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我该如何摆脱两个循环.我看过类似的问题,但答案可以在java中找到我想要的c ++.
我必须在我的程序中调用一个函数100000次.如果传递给函数的参数是4,那么如果传递的参数是5则返回5,它返回4.我有以下两个函数执行相同的任务,一个使用减法,另一个使用除法运算.我需要最快的代码.哪一个更好,为什么.
int function1( int x)
{
return 9-x;
}
int function2(int x )
{
return 20/x;
}
Run Code Online (Sandbox Code Playgroud)