0

I recently installed xeus-cling using below command,

conda install xeus-cling -c conda-forge

It is working fine for other function but for below function I am getting error,

pair<int,int> max_min_array(int *arr, int n) {
  int min = arr[0], max = arr[0];
  for(int i=1;i<n;i++) {
    if(arr[i] < min) 
      min = arr[i];
    else if(arr[i] > max) 
      max = arr[i];
  }
  return make_pair(min,max);
}

error

input_line_9:2:47: error: function definition is not allowed here
 pair<int,int> max_min_array(int *arr, int n) {
                                              ^

Interpreter Error: 

Before that function cell, I have another cell where I am importing

#include<iostream>
#include<utility>
using namespace std;

My Observation

below function works fine,

int max_min_array(int *arr, int n) {
  int min = arr[0], max = arr[0];
  for(int i=1;i<n;i++) {
    if(arr[i] < min) 
      min = arr[i];
    else if(arr[i] > max) 
      max = arr[i];
  }
  return min;
}
PSKP
  • 1,178
  • 14
  • 28
  • This usually means you're missing one or more closing curly brackets (`}`) in the function that is right before this one. – 1201ProgramAlarm Oct 17 '21 at 17:13
  • I am not missing anything. I checked number of times – PSKP Oct 17 '21 at 18:16
  • I'm running into same problem (different function). Xeus-cling works fine for some f() but not others. Also seems xeus-cling remembers that it is using some namespaces from previous code cells, but not others. These glitches are without pattern? – Don Slowik Jan 17 '22 at 21:30
  • I'm still getting familiar with xeus-cling so I could be mistaken, but I believe I'm beginning to see a pattern: If you define a function in the top-level scope of a cell, that's the only thing that can go in that cell. Ran into this with using statements and some variable definitions outside the function definition once; after moving them inside the function all my troubles went away. – jboley-arnl Jan 03 '23 at 01:17

0 Answers0