Just Game Dev Just Game Dev - 11 months ago 54
C++ Question

How to access a function from a class?

How do you access a function from a class, outside of that class?


int main(int argc, char *argv[])
class ImageLoading

void Loading()
cout << 5 <<endl;



return 0;

Answer Source

A standard function defined in a class is an instance class. It can be used only on an instance, i.e. a created object. To do that, you need to create an ImageLoading class instance:

ImageLoading instance;

It is possible too to create functions associated to the class and not to its instances. For that, you need to add the keyword static in the function definition

static void Loading()
    cout << 5 << endl;

Then to use it, you need to tell that it is the static class defined in ImageLoading. The syntax is ClassName::MethodName() so: