I usually use forward declaration predominantly, if I have a class that does not need complete definition in .hpp file
Ex)
//B.hpp
namespace A_file {
class A;
}
namespace B_file {
class B {
public:
B();
private:
A *ptr_to_A;
}
}
//B.cpp
#include "A.hpp"
using namespace A_file;
namespace B_file {
B(int value_) {
*ptr_to_A = new A(value_);
}
int some_func() {
ptr_to_A->some_func_in_A();
}
}
I write this kind of code. I think, it will save including the whole hpp again. (Feel free to comment, if you thing, this is not healthy)
Is there a way that I can do the same for objects/classes in std namespace? If there is a way, is it okay or does it have side effects?
See Question&Answers more detail:os