error invalid aunary in small program

Hi I am trying to compile a program and receive 2 errors. One is on line 22 which stats "invalid type argument of aunary" and line 22 "declaration of double pa shadows a parameter". Also on line 26 it states "invalid types double [int] for array subscript. Does anyone have any tips to get started?
Last edited on
You already declared p as a parameter of your function.
Write something like:
 
double q = *p++;
Okay thanks I updated it, but do you know why I am getting the 2 error messages line 26 it states "invalid types double [int] for array subscript and In function âvoid extend(double*, double*, double*, int)â:
By declaring q on line 22, you make it impossible to access the q that is the function parameter (this is why it says it "shadows" the parameter). So line 26 is trying to use an array subscript on the q you declared on line 22, which is invalid.
so can I fix that by adding a constructor initialization list? []
You can fix that by changing the name of the q in you declared in extend(). Also, though this is a small program, it could end badly if you didn't pass an array of doubles, but the address or a pointer to a double variable, because line 22 would increment p to a junk block. You can fix this by taking arrays as the parameter to the function.
Last edited on
Sorry I am not fully understanding if I change the q into something like r then what would r be used for in extend()? Is there any fast fix to get it to at least compile?
Last edited on
Yes. As I said, you just need to change the name of the variable q like this:
1
2
3
4
5
6
7
8
9
10
11
void extend(double *p, double *q, double *a, int c)
{

 double r = *p++;
  cout << r;
  for(int i = 1; i < 10; i++)
    {
   cout << q[i];
    }

}
Topic archived. No new replies allowed.