Since I started learning C ++ I've always done something like:
class.h
#ifndef CLASSE_H
#define CLASSE_H
class OutraClasse;
class Classe
{
public:
Classe();
void foo(OutraClasse *bar);
};
#endif
And here I declare methods, constructor and other things classe.cpp :
#include "classe.h"
#include <OutraClasse>
Classe::Classe()
{
//Algo aqui
}
void Classe::foo(OutraClasse *foo) {
//Algo aqui
}
But note that eventually some classes are only written in .h
like this:
#ifndef CLASSE_H
#define CLASSE_H
#include <OutraClasse>
class Classe : public OutraClasse
{
public:
Classe() {
//Algo aqui
}
void foo(OutraClasse *bar) {
//Algo aqui
}
};
#endif
main.cpp would look something like both:
#include "classe.h"
#include <OutraClasse>
int main()
{
OutraClasse outra;
Classe foobar;
foobar.foo(&outra);
}
I'd like to know if this influences compilation or post-compilation, for example running, this is because of the declaration order of the headers , I mean, if I understood correctly the first example I mentioned works great would only call OutraClasse
when foobar
is used, in the second example it would be called at all times.
Is there a difference for compilation, performance or performance?