Problems with running a simple macro

Hi everyone

To start off I should say that I am new to ROOT and fairly new to c++. I have written a macro for pulling out the maximum value in a vector array shown here: double maxvalue(std::vector<double> array) { length = array.size(); int max = array[0]; for (int i=0; i<length; i++) { if (array[i]>max) { max=array[i]; } } return max }

I can’t see anything wrong with this code but everytime I try to run it this error gets returned:
Error: Missing closing brace for the block opened around line 3.
Error: Unexpected end of file (G__exec_statement()) /home/stephen/snoing/csvfiles/maxvalue.C:15:

I checked my braces and used brace matching on emacs (even though its only 3 braces). Does anyone have any idea why this is happening?

ps: I know this doesn’t contain ROOT specific problems but I couldn’t think of any other reason for it not working than an issue with CINT.




double maxvalue(std::vector &array)
unsigned long length = array.size();
if (length < 1) return 0; // just a precaution
double max = array[0];
for (unsigned long i = 1; i < length; i++)
if (array[i] > max)
max = array[i];
return max;

Thankyou very much, It seems it was the missing “;” after the return that was messing it up. Not feeling like the smartest guy after stressing over this for an hour without seeing that. :laughing: