xeus-cling icon indicating copy to clipboard operation
xeus-cling copied to clipboard

function definition is not allowed here

Open mossishahi opened this issue 4 years ago • 4 comments

Hi I have searched many issues over your github telling the same story, still, I was wondering to know if there is any update or solution for my problem:

#include <iostream>
#include <string>
using namespace std;
const int MAX = 1000;

int EditDistance(string A, string B) {
cout << A << B << endl;
}

int main(int argc, char* argv[]){
    string A, B;
    cin >> A;
    cin >> B;
    cout << EditDistance(A, B);
    return 0;
}

error:

input_line_25:4:38: error: function definition is not allowed here
int EditDistance(string A, string B) {
                                     ^
input_line_25:7:33: error: function definition is not allowed here
int main(int argc, char* argv[]){
                                ^
Interpreter Error: 

just to mention that all of the code lines are in a same cell.

Regards

mossishahi avatar Apr 21 '20 14:04 mossishahi

Quick note, unrelated to this issue:

You don't need to specify main in xeus-cling.

SylvainCorlay avatar Apr 21 '20 14:04 SylvainCorlay

I'm having the same problem. @SylvainCorlay how woud you refactor the above code to make it work?

nyck33 avatar Apr 27 '20 06:04 nyck33

You first need to get rid of the main function, you can see the entire Notebook as the main. And if you get an error: function definition is not allowed here, please be sure to define your function in a separate cell with no code before the definition.

martinRenou avatar Apr 27 '20 07:04 martinRenou

Thanks.

nyck33 avatar Apr 27 '20 17:04 nyck33