Invoke a c++ class method without a class instance?

Use the keyword ‘static’ to declare the method:

static int MyMethod( int * a, int * b );

Then you can call the method without an instance like so:

int one = 1;
int two = 2;

MyClass::MyMethod( &two, &one );

‘static’ methods are functions which only use the class as a namespace, and do not require an instance.

Leave a Comment