Reputation: 1
When I run this code, I receive the following error:
invalid type argument of unary '*' (have 'int')
How can I clear this up?
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
void multiplyFive (int &x, int y, int *z){
int d = 5 * x;
int e = 5 * y;
int f = 5 * *z;
cout << d << " " << e << " " << f << endl;
}
int main() {
int a = 2;
int *b = &a;
int &c = *b;
multiplyFive (a, b, *c);
return EXIT_SUCCESS;
}
Upvotes: 0
Views: 845
Reputation: 123084
Clangs error message is a bit more helpful:
<source>:19:21: error: indirection requires pointer operand ('int' invalid)
multiplyFive (a, b, *c);
^~
c
is a reference to an int
not a pointer, you cannot dereference it via *
.
It seems like you mixed up 2nd and 3rd parameters to multiplyFive
, because the next error you will receive is that b
is a int*
but multiplyFive
expects a int
in its place.
Upvotes: 1