Hi Ben,
I'm working on my first flext project. I'm slowly getting the hang on
things (c++ in particular) I need to create an array with the number of elements specified by the creation arguments of the object. I also need this array to be available to all functions in the class.
How to I create the array? Where do I define it? (in the constructor?)
then how do I access it from another function?
The typical solution is to put the array variable as a member into the class structure, to initialize it in the constructor and to free the memory in the destructor again. If it's a member of the class you can access it from any class member function. Of course then you'll have to know the size of the array at object creation time, either because it is constant (e.g. defined by a #define) or because you get it with the object creation arguments.
e.g. something like that (not tested...):
class myclass: public flext_base { FLEXT_HEADER(myclass,flext_base)
public:
myclass(int size) { arr = new float[size]; AddOutInt(); FLEXT_ADDMETHOD_(0,"poke",poke); }
~myclass() { delete[] arr; }
// get an indexed sample of the array void poke(int ix) { ToOutFloat(0,arr[ix]); }
float *arr;
FLEXT_CALLBACK_I(poke) };
FLEXT_NEW_1("myclass",myclass,int)
best greetings, Thomas