error: ambiguous overload for 'operator/'
I am new to c, and the following is giving me some grief:
int i,j,ll,k;
double ddim,ddip,ddjm,ddjp,ddlm,ddlp;
for(i=1; i<(mx-1); i++){
for(j=1; j<(my-1); j++){
for(ll=1; ll<(mz-1); ll++){
ddim=0.5*k
ddip=0.5*k
ddjm=0.5*k
ddjp=0.5*k
ddlm=0.5*k
ddlp=0.5*k
Wijl(i,j,ll) = ((1.0/h_x)*(ddip) \
((1.0/h_x)*(ddim)) \
((1.0/h_y)*(ddjp)) \
((1.0/h_y)*(ddjm)) \
((1.0/h_z)*(ddlp)) \
((1.0/h_z)*(ddlm)) ;
}
}
}
I then compile this with gcc using python and scipy, passing it everything that is not initialized, but I know the problem is in the 1.0/h_x part of the code. If I compile basic c statements using python/gcc it works, so I am not having a python开发者_StackOverflow中文版/gcc issue.
The error I am getting is: "error: ambiguous overload for 'operator/' in '1.0e+0 / h_x'
It seems like it is trying to do assignment overloading, and all I want to do is division!
Any help would be greatly appreciated! :)
Thanks,
Tyler
I think it's trying to say that it's not clear what type h_x is, so it doesn't know which of the overloaded / operators to use (double/int, double/double, etc). You could try casting it (h_x) to int or double to tell it what version to use.
If h_x
is float
then dividing 1.0
(by default double
) by it leaves C wondering whether to do the operation in float or double math.
If you want to do it in floats, change 1.0
to 1.0f
; if double, either declare or cast your h_x
to double
.
If h_x
is int
(that's what I'm afraid of) you'd probably do well to assign your h_?
's to three corresponding float or double temp variables outside the loop, to save the compiler from (possibly) doing lots of unnecessary int-to-float conversions. As a side effect, this will make your type ambiguity go away.
You could also simplify the code a bit by getting rid of those 1.0
's: Instead of multiplying by the reciprocal, you could simply divide those expressions by h_whatever
. Especially as the right half of each of those lines is already doing something similar.
I strongly suggest that you carefully peal off all of the utterly redundant parentheses and examine carefully what is left.
For example, this snippet:
((1.0/h_x)*(ddim)*((q(i,j,ll) - q(i-1,j,ll)))/h_x)
boils down to:
ddim * (q(i,j,ll) - q(i-1,j,ll)) / h_x / h_x
Note that the original separation of the two occurrences of / h_x
makes one wonder what the original intention was.
精彩评论