error: function definition is not allowed here in xeus-cling

345 Views Asked by At

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

There are 0 best solutions below