the MyClass object is defined in the setup() function scope, and thus, only setup() body can see it, the3re are billions of workarounds depending on the code structure, one possibility would be to pass it as a parameter
#include "DarkGDK.h"
#include "classes.h"
void setup( );
void DarkGDK( )
{
MyClass myObject;
setup( &myObject );
while( LoopGDK( ) )
{
myObject.function( );
}
}
void setup( MyClass* obj )
{
if ( obj )
obj->function();
}
*note: a pointer is passed, because parameters only contain a copy of the object, you could also pass a reference, or have another solution, it's up to you
or define the object in global scope
#include "DarkGDK.h"
#include "classes.h"
MyClass myObject;
void setup( );
void DarkGDK( )
{
setup( );
while( LoopGDK( ) )
{
myObject.function( );
}
}
void setup( )
{
myObject.function( );
}
Quote: "I'm still new to classes myself but I didn't think you could define classes inside functions... Have you tried setting up the class before the setup function?
If I'm wrong I would love to know"
no that's wrong, you can create a class instance/object inside functions or anywhere you want, as long as it knows that the class is defined (that means the class must be in a viewable scope for the function), you could even define the whole class body inside a function, like
void func ( void )
{
class myClass
{
int x;
public:
myClass ( void )
{
x = 0;
};
void setx ( int val )
{
x = val;
};
};
myClass obj;
obj.setx ( 10 );
}