小编Ari*_*gri的帖子

通过静态方法返回当前对象

我想返回一个类的当前对象。由于 $this 变量指的是该类的当前对象,但是当我返回 this 时,我收到一个错误。

这是我的代码

class Test{
    $name;
    public static function getobj($n){ 
        $this->name; return $this; 
    }
}
$obj= Test::getobj("doc");
Run Code Online (Sandbox Code Playgroud)

php

2
推荐指数
1
解决办法
3620
查看次数

打破嵌套循环C++

我有一个这样的嵌套循环结构:

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 ++.

c++

-1
推荐指数
1
解决办法
589
查看次数

一个函数的性能分析

我必须在我的程序中调用一个函数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)

c++ performance

-3
推荐指数
1
解决办法
197
查看次数

标签 统计

c++ ×2

performance ×1

php ×1