The "Inside the class" (I) method does the same as the "outside the class" (O) method.
However, (I) can be used when a class is only used in one file (inside a .cpp file). (O) is used when it is in a header file. cpp files are always compiled. Header files are compiled when you use #include "header.h".
If you use (I) in a header file, the function (Fun1) will be declared every time you include #include "header.h". This can lead to declaring the same function multiple times. This is harder to compile, and can even lead to errors.
Example for correct usage:
File1: "Clazz.h"
//This file sets up the class with a prototype body.
class Clazz
{
public:
void Fun1();//This is a Fun1 Prototype.
};
File2: "Clazz.cpp"
#include "Clazz.h"
//this file gives Fun1() (prototyped in the header) a body once.
void Clazz::Fun1()
{
//Do stuff...
}
File3: "UseClazz.cpp"
#include "Clazz.h"
//This file uses Fun1() but does not care where Fun1 was given a body.
class MyClazz;
MyClazz.Fun1();//This does Fun1, as prototyped in the header.
File4: "AlsoUseClazz.cpp"
#include "Clazz.h"
//This file uses Fun1() but does not care where Fun1 was given a body.
class MyClazz2;
MyClazz2.Fun1();//This does Fun1, as prototyped in the header.
File5: "DoNotUseClazzHeader.cpp"
//here we do not include Clazz.h. So this is another scope.
class Clazz
{
public:
void Fun1()
{
//Do something else...
}
};
class MyClazz; //this is a totally different thing.
MyClazz.Fun1(); //this does something else.