我是C ++的初学者,我的代码中出现两个错误,而且我不知道如何解决它们。
第一个


  非法间接


第二个是


  左操作数'='必须是I值。 (在该行中:(((ArrayPtr + i)+ j)= rand()%55 + 1)


有谁知道如何修复它们?那是我的代码:

#include <iostream>
#include <math.h>
#include <time.h>
#include<iomanip>
#include<array>
#include <algorithm>
using namespace std;
const int AS = 6;
void FillingRandomly(int (*)[AS]);
void printing(int (*)[AS]);
int c;
int main()
{
    int funny = 0;
    int timpa = 0;
    int counter = 0;
    int Array[AS][AS];
    srand(time(0));
    FillingRandomly(Array);
    cout << "The unsorted array is" << endl << endl;
    printing(Array);
    cout << "The sorted array is" << endl << endl;
    printing(Array);
    system("PAUSE");
    return 0;
}
void FillingRandomly(int *ArrayPtr)
{
    for(int i=0;i<AS;i++)
    {
        for (int j=0;j<AS;j++)
        {
            *(*(ArrayPtr +i)+j)=rand()%55+1;
        }
    }
}
void printing(int *Array)
{
    for(int i=0;i<AS;i++)
    {
        for (int j=0;j<AS*AS;j++)
        {
            int counter = 0;
            cout<<((Array[i] +j))<<setw(5);
            if ((Array[i] +j)%AS == 0)
            cout << endl << endl;
        }
    }
}
void forsorting(int *Brray, int funny)
{
    int dice = 0;
    int super = 0;
    int space=0;
    //Sorting Array[][] which is treated like Array[]
    {
        for (int pass = 0; pass < AS - 1; pass++) {
            for (int k = 0; k < AS - 1; k++) {
                int temp;
                if(*(Brray+k)==*(Brray+k+1))
                {
                    temp=*(Brray+k);
                    *(Brray+k)=*(Brray+k+1);
                    *(Brray+k+1)=temp;
                }
            }
        }
    }
}

最佳答案

通过

*(*(ArrayPtr +i)+j)=rand()%55+1;


看来你要

ArrayPtr[i][j] = (rand() % 55) + 1;


您可以尝试以下方法

int const offset = AS * i + j;
int const elem = (rand() % 55) + 1;
*(ArrayPtr + offset) = elem;

09-11 19:43