Using C++ Classes

Monkey Forums/Monkey Programming/Using C++ Classes

Suco-X(Posted 2011) [#1]
Hi Guys.

I bought monkey last saturday and I´m testing. Well, now I got a question. You can do something like this:

Strict 

#if TARGET="glfw"
	Import "supi.cpp"
#else
	Import "supi.js"
#endif


Extern 
	Function SomTest:Int(a:Int, b:Int)="Add"
Public 


Function Main:Int()
	Print SomTest(300,400)
	Return 0
End Function 


Supi.cpp:

#include <iostream>

using namespace std;


int Add(int a, int b)
{
	cout << "C++" << endl;
	return a+b;
};



Supi.js

function Add(a,b)
{
  return a+b;
}


This means, you can write your own version for your fav. target. But how can I declare a class in C++ and use it with monkey as a normal class?
Got problems with the constructor, someone has experience with this part of monkey?

Mfg Suco


JaviCervera(Posted 2011) [#2]
As posted here, Monkey cannot directly call C++ constructors.


Brucey(Posted 2011) [#3]
Yeah, it's a shame about that. It makes it rather more complicated to use third party libraries (than it could be).


JaviCervera(Posted 2011) [#4]
Yeah, you need to add your own .cpp file when using external libraries providing Create functions for all objects.