what does it means if function or struct that declares outside the class

Hello all
i notice that there something like declaring function outside of class
what does it means ?
for example :

this is the header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void * getSomething(); 

struct B {
    char* f;
};

class A {
...
...
};


and then the implementation if like this : 

viod* getSomething(){
...
...
}


what is the meaning of such thing ?
why is it outside the class ?
It's a C++ convention for class implementation.

Class declarations are usually on a header file(.h). This includes, but not limited to, member declarations, assignment of default values, function prototypes, and library dependencies.

Class definitions/implementation are usually on a .cpp file. Here, the functions prototypes are defined, etc.

One more thing to know is that all functions/method defined inside a class declaration is implicitly inline.

EDIT: I just realized that the function above is a global function.

If a function is global, then it can be called by any eligible entity in the code. In the above case, both class A and B can call getSomething().
Last edited on
Topic archived. No new replies allowed.