Expected expression error?

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;
Do you get the error on the line that you have written (!EXPECTED EXPRESSION!) or is that part of the code?
Last edited on
Yes
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.
All it says on the side is "Parse Issue
Expected Expression"
Can you post a complete example that can be compiled and gives this error?

{
}

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;
}

Remove the
1
2
{
}
Alright I did that, but i'm still getting the same error message
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.