Expected expression error?

Sep 23, 2012 at 8:18pm
Can anyone tell me whats going wrong with this program? Trying to implement the trapezoidal rule:

template <class ContainerA, class ContainerB> (!EXPECTED EXPRESSION!)
double trapezoid_integrate(const ContainerA &x, const ContainerB &y) {
if (x.size() != y.size()) {
throw std::logic_error("x and y must be the same size");
}
double sum = 0.0;
for (int i = 1; i < x.size(); i++) {
sum += (x[i] - x[i-1]) * (y[i] + y[i-1]);
}
return sum * 0.5;
Sep 23, 2012 at 8:24pm
Do you get the error on the line that you have written (!EXPECTED EXPRESSION!) or is that part of the code?
Last edited on Sep 23, 2012 at 8:24pm
Sep 23, 2012 at 8:30pm
Yes
Sep 23, 2012 at 8:36pm
Can you give the exact error message? My guess is that you have some problems in the lines above (like a missing ;) or that the error has something to do with the template arguments you use.
Sep 23, 2012 at 8:39pm
All it says on the side is "Parse Issue
Expected Expression"
Sep 23, 2012 at 8:55pm
Can you post a complete example that can be compiled and gives this error?
Sep 23, 2012 at 8:58pm

{
}

template <class ContainerA, class ContainerB>
double trapezoid_integrate(const ContainerA &x, const ContainerB &y) {
if (x.size() != y.size()) {
throw std::logic_error("x and y must be the same size");
}
double sum = 0.0;
for (int i = 1; i < x.size(); i++) {
sum += (x[i] - x[i-1]) * (y[i] + y[i-1]);
}
return sum * 0.5;
}

Sep 23, 2012 at 9:08pm
Remove the
1
2
{
}
Sep 23, 2012 at 9:22pm
Alright I did that, but i'm still getting the same error message
Sep 23, 2012 at 9:26pm
closed account (zb0S216C)
I can think of a few reasons as to why you're receiving your error message:

1) You're missing either a closing brace/parenthesis/bracket/angle-bracket, or a semi-colon before the troublesome line.

2) You're declaring the template parameters "ContainerA", and "ContainerB", which are currenly in use somewhere else in your code.

Wazzak
Topic archived. No new replies allowed.