Hello,
I have built a small math parsing library, which compiles just fine, but when I integrate it into any programs I get these errors:
1 2
error: 'std::pair<_T1, _T2>::second' has incomplete type
error: forward declaration of 'struct Operator'
Operator is defined in Ub3rParse.h (Header internal to the library) and referenced in Ub3rMath.h (The external header for the library) as: struct Operator;
Ub3rMath.h line 49: typedef unordered_map<string, Operator> OperatorList;
I know it is caused by Operator being defined in the library but only referenced as struct Operator (as a prototype) in the external header. I just don't know how to fix it without significantly complicating things.
You will need to actually define Operator or use pointers to Operator in your list and deal with the runtime allocation, etc. Not many other ways around it I can see.
You are only declaring Operator in Ub3rMath.h. You actually define it in Ub3rParse.h. In order for the typedef to make any sense Operator must be both declared and defined beforehand. Why not #include Ub3rParse.h in Ub3rMath.h and eliminate the forward declarations?
Things like this still frustrate me as well. Would it be a horrible task to change the unordered_map to take a pointer to Operator and manage the allocation/tasks internally?
Again, why can you not include a definition of Operator in the Operator hearder? THis is normally how things are done; you cannot define functions in a class that has only been forward declared. You need a full definition for it to work.
If you cannot do this, that is a huge design flaw and you need to redesign your library.
the library has a header for internal use called Ub3rparse.h, there is also a wrapper class to provide a simple interface to programs using the library. The header for that class is Ub3rMath.h -- Which is thus also used by the external programs. But because both libraries are included in the library at compile time, the definition can not be in both or an error occurs. If I am doing this the wrong way, I apologize; I am still a student and this is the first library I try to build.
You need to have one header for both external and internal use - if you have to use a #define to tell whether it is being used internally or externally, that is also wrong.
The header should give the definitions of classes and their function prototypes only, the actuall implementation is your 'library'.