2
int main (void)
{
    int** arr = new int*[4];
    for (int i = 0; i < 4; i++) arr[i] = new int[4] {1, 0, 0, 1};

    const int* p = &(arr[0][0]);

    TFigure* test = new TFigure(arr, 4, 4);
    test->resolve();

    for (int i = 0; i < 4; i++) delete[] arr[i];
    delete[] arr;

    return 0;
}

where constructor declaration is line 57:

TFigure(int **ia, int n, int m)
    N = n;
    M =m;

    landscape = new int*[n];
    puddles = new int*[n];
    for (int i = 0; i < n; i++){
        landscape[i] = new int[m];
        puddles[i] = new int[n];
        for (int j = 0; j < m; j++)
            landscape[i][j] = *ia[i][j];
        }


    for (int i = 0; i < n; i++)
        for (int j = 0; j < 0; j++)
            if (i == 0 || i == N || j == 0 || j == M)
                puddles[i][j] = 0;
            else
                puddles[i][j] = 1;

    for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++)
    std::cout << puddles[i][j] << ' ';
    std::cout << std::endl;
    }
    for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++)
    std::cout << landscape[i][j] << ' ';
    std::cout << std::endl;
    }


};

but I have an error

57:43: error: invalid type argument of unary «*» (have «int»)

I don't understand what causes this.

6
  • 4
    Which line is line 57? Commented Mar 9, 2013 at 12:02
  • 3
    Your code should work. Please show the whole definition of TFigure Commented Mar 9, 2013 at 12:03
  • 2
    agree with Andy Prowl above. btw, don't forget to delete test; as well. Commented Mar 9, 2013 at 12:08
  • What is that int* p used for? That variable doesn't make sense given that arr is a ragged (or jagged) array. Why is that declaration even there? You aren't using p in the code shown. And finally, what is line 57? Commented Mar 9, 2013 at 12:10
  • 1
    Please don’t use pointers here Commented Mar 9, 2013 at 12:12

1 Answer 1

2

The problem is with this line:

landscape[i][j] = *ia[i][j];

ia[i][j] gives you an int which you then try to dereference. It seems like you really just want:

landscape[i][j] = ia[i][j];

I'm not sure if this was a mistake when copy and pasting or not, but your constructor definition is missing an opening {.

TFigure(int **ia, int n, int m) {
//                         Here ^
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.