Declare the instance as a global. I have no idea what class you're working with, so I'm making up names.
SomeClass myInstance = SomeClass(someParams);
void setup()
{
myInstance.doSomething();
}
void loop()
{
some_other_func();
}
void some_other_func()
{
myInstance.doSomething();
}
Alternatively, if you want to control WHEN it's constructed, declare a global pointer to the instance, and make the instance when you're ready.
#include <stdlib.h> // for malloc and free
void* operator new(size_t size) { return malloc(size); }
void operator delete(void* ptr) { free(ptr); }
SomeClass* ptrToMyInstance = NULL;
void setup()
{
// get ready
ptrToMyInstance = new SomeClass(someParams);
ptrToMyInstance->doSomething();
}
void loop()
{
some_other_func();
}
void some_other_func()
{
ptrToMyInstance->doSomething();
}
And finally, if you don't want to include the overhead of defining new/delete, or you want to pass addresses to functions reliably,
void setup()
{
SomeClass myInstance = SomeClass(someParams);
myInstance.doSomething();
some_other_func(&myInstance);
}
void some_other_func(SomeClass* ptrToMyInstance)
{
ptrToMyInstance->doSomething();
}