6
Ever 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 the methods, builder and other things cpp class.:
#include "classe.h"
#include <OutraClasse>
Classe::Classe()
{
//Algo aqui
}
void Classe::foo(OutraClasse *foo) {
//Algo aqui
}
But I notice that eventually some class are written only in .h
thus:
#ifndef CLASSE_H
#define CLASSE_H
#include <OutraClasse>
class Classe : public OutraClasse
{
public:
Classe() {
//Algo aqui
}
void foo(OutraClasse *bar) {
//Algo aqui
}
};
#endif
The main.cpp would look something like both:
#include "classe.h"
#include <OutraClasse>
int main()
{
OutraClasse outra;
Classe foobar;
foobar.foo(&outra);
}
I would like to know if this influences the compilation or post-compilation, for example execution, this due to the statement order of headers, I mean, if I understood correctly the first example I quoted works very just call OutraClasse
when foobar
is used, in the second example it would be called at all times.
Is there any difference for compilation, execution or performance?
I guess you didn’t like the answer, even if I gave you a hint, I could try to improve :)
– Maniero
@Maniero or will see that I personally am too bad to understand some things and was ashamed to admit it. I have to say that I really need time and a little organisation to get to the bottom of this. But I promise I will review all my questions and you will have my feedback - Thank you !
– Guilherme Nascimento