0

I know this is a bit remedial but I cant seem to understand my problem. It probably has something to do with the parameters in the arguments but im not sure.

void Input (int **&x, int *&arr, int &size1,int &size2, int a, int b)
{

    cout << "Please enter 2 non-negative integer values: "<< endl;
    cout << "1. ";
    cin >> size1;
    int checkVal(int size1, int a);
    cout << "2. ";
    cin >> size2;
    int checkVal(int size2, int b);

    void putArr(int **&x,const int &size1,const int &size2);

    arr[0] = size1;
    arr[1] = size2;

}


int checkVal (int &size, int x)
{
    do{
    if (size < 0)
        cout << size << " is not a non-negative integer. Re-enter --> " << x << ". ";
        cin >> size;
    }while(size < 0);

    return size;

}



void summation(int ***&y, int *&arr)
{
    int *size = new int;

    *size = **y[0] + **y[1];
    y[2] = new int *(size);

    *(arr + 2) = *size;

    delete size;

}

int main()
{
    int size, size1, size2;
    int a = 1, b = 2;

    int** x;
    int*** y;
    int** q;
    int**** z;

    int *arr[2];

    allocArr(x, y, q, z);
    Input(x, arr, size1, size2, a, b);
    checkVal(size);
    putArr(x, size1, size2);
    summation(y, arr);
    display(z);


}

The problem occurs with all three of these functions. Im quite confused. Thank you in advanced.

2
  • 1
    Why are you mixing pointers and references? For example int ***&y can simply be int*** y. Commented Sep 8, 2014 at 23:08
  • To address your question more directly: what line causes the error? What is the exact, full error message? Commented Sep 8, 2014 at 23:09

2 Answers 2

2

Not mentioning the stars with unknown intended purpose, you have code like this in several places:

cin >> size1;
int checkVal(int size1, int a);
cout << "2. ";

Here you declare function checkVal, not call it. In this particular case I beleive it should be replaced to

cin >> size1;
cout << "2. " << checkVal(size1, a);

(provided you supply arguments of right types)

Sign up to request clarification or add additional context in comments.

Comments

0
Input(x, arr, size1, size2, a, b);
// ...
summation(y, arr);

The problem in both of these cases is the second argument, arr. It is of type int*[] (array of pointer to int), which can decay into the type int** (pointer to pointer to int), but this type is not compatible with the parameter type int*& (reference to pointer to int).

checkVal(size);

This fails because the function accepts two arguments but you pass only one, and the remaining arguments do not have default values.

There are numerous other problems in this code, but this addresses your question regarding why the invocations of these functions fails to compile.

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.