I've looked around and I can't quite tell if the other similar questions answer this or not.
// lib.h
namespace lib_namespace
{
struct lib_struct
{
typedef std::vector<LibObject> struct_value;
};
typedef lib_struct::struct_value lib_value; // compiler points here
};
// my.h
// attempt at forward declaration
namespace lib_namespace { class lib_value; };
...
// my.cpp
#include "lib.h"
I get a redefinition compiler error which is understandable, but is there a way to forward declare that typedef?
My intent is to avoid adding lib.h as a dependency outside of the library I'm making. Perhaps there's a better way to achieve that?
Edit: To clarify, I'm trying to avoid adding an additional include directories line to all the project files that would use the library I'm creating because of the third party library I'm using and the above situation is where I'm stuck. So it's OK if I include lib.h
in my.cpp
, but not my.h
.
You compiler complains, because lib.h
and my.h
are independent header files and they don't know about each other. Moreover, unlike the actual class
, the typedef
doesn't support the forward declaration.
Suppose, you don't want to #include"lib.h"
, then you can create a separate header which has typedef lib_struct::struct_value lib_value;
and the relevant part related to it. #include
that new header wherever needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With