I do not quite understand what does :: do?
It's the scope resolution operator.
If foo
is a class (or a namespace), and foofa
is something declared inside that class, then within the class you can refer to it simply as foofa
. But outside the class, you need to use this operator to specify that you mean this particular foo::foofa
; there could be others scoped inside other classes or namespaces.
Also, is there another way to write this without the ::
or is it required?
It's required outside the class definition. You could define the function inside the class:
class foo {
void foofa(string n) { // No foo:: needed here
loadFoo(n);
}
};
If foo
is a namespace, then you can also use using
to avoid the need for ::
but that's often a bad idea, so I won't show you how.