注册 登录
编程论坛 C++教室

高手们,我的程序怎么错了呢

weiwei859 发布于 2011-06-05 13:15, 550 次点击

在这个程序中,我想return 2 个数 count and succeN. 为什么不对呢

double N_loop(int m, int n, Matrix A,int *b, int N)
{
        double count=0;
        double succeN=0;
        double N1=0;
        double one;
        int bnew[m];
        double sum;
        for (int i=0;i<N;i++)
        {
        for (int i=0;i<m;i++) bnew[i]=b[i];
        one=oneLoop( m, n, A,b,bnew);           
        if (one < 0) count++;
        else { sum+=one;N1++;}
        }
        
        if (N1>0) succeN=sum/N1;
        if (N1==0) succeN=-1;
        double *point;
        *point=count;
        *(point+1)=succeN;
        return point;
                  
}
3 回复
#2
lintaoyn2011-06-05 13:56
double *point = new double[2];//这把句改了
如果你不想了解太多可以按下面说的理解。
指针指向的地址应该是合法的可用地址。
double *point;这样写point指向的地址是不一定能使用的。(你也可能以理解成point指向的地址是不可用的)
#3
fangdong652011-06-05 14:08
返回多个值可以用指针参数啊
#4
weiwei8592011-06-05 18:40
那要怎么改呢,还是不太明白
我可以这么做,但是为什么我的cout 出来总是0 0
void reasian(int n, int b)
{
        n=5;     b=6;

}


int main(int argc, char *argv[])
{
        int n1=0;
        int b1=0;
        reasian(n1, b1);
        
        cout << n1<< " "<< b1 << endl;

       return 0;
}




[ 本帖最后由 weiwei859 于 2011-6-5 19:03 编辑 ]
1