2

I have installed cling kernel for using C++ in Jupiter notebook but after implementing the code

#include <iostream>
using namespace std;

int main() {

  int a;
  a=9;
  cout<<a;
  return 0;
 }

I am getting an error as ---> error: function definition is not allowed here int main() {

AbtabM
  • 129
  • 10

1 Answers1

2

In cling you don't write the whole program code. It's like a script language. You just write the lines that should be evaluated. Don't write the main function:

#include <iostream>
using namespace std;

int a;
a=9;
cout<<a;

You can also define functions in cling but then you are not allowed to write other code into the same cell.

Thomas Sablik
  • 16,127
  • 7
  • 34
  • 62
  • It Works well in C++ kernel 14,but getting an error in C++17. Thanks @Thomas – AbtabM Jul 06 '20 at 08:35
  • 1
    @AbtabM That's strange. It should also work in C++17 kernel. You can check the documentation https://github.com/jupyter-xeus/xeus-cling and the online platform https://hub.gke.mybinder.org/user/jupyter-xeus-xeus-cling-9p0ammy1/notebooks/notebooks/xcpp.ipynb I'm not experienced with cling so I can't help any further. – Thomas Sablik Jul 06 '20 at 08:43
  • Thanks A lot , i'll check the documentation too – AbtabM Jul 06 '20 at 09:04
  • I can define then call the function in same cell… – Don Slowik Jan 25 '22 at 13:42