C++ objects and Lists

Monkey Forums/Monkey Programming/C++ objects and Lists

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

I´m just testing arround with monkey and now I got a further question.

C++ Code (test.cpp):

class CTest
{
public:
	int v1, v2;

	CTest(int _v1, int _v2){
		v1 = _v1;
		v2 = _v2;
	};



};


CTest* CreateTest(int v1, int v2)
{
	return new CTest(v1, v2);
}




Monkey Code:

Import "test.cpp"

Extern

Function CreateTest:CTest(v1:Int, v2:Int)

Class CTest
	Field v1, v2
End

Public 

Function Main()
	Local l:List<CTest> = New List<CTest>
	l.AddLast(CreateTest(200,200))

End 



Why I can`t save an CTest object in a List? If I create a single CTest object, I can work with it. So, why not in a List?
Would be pleased about an explanation.
Thank you.

Mfg Suco


marksibly(Posted 2011) [#2]
Hi,

C++ objects that you want to be accessible from Monkey should extend the 'Object' class, eg:

class CTest : public Object {...etc...}

The Object class is declared in modules/monkey/native/lang.cpp


Suco-X(Posted 2011) [#3]
Hi Mark,

runs fine, thank you very much.

Mfg Suco