Okay guys, this is a follow up to one of my previous questions and I have come up with a possible solution to my project and I need some advice or guidance if I have this right.
Basically my project is a library to be used and compiled on both Linux and Windows, the Linux part isn't much of an issue, its Windows.
My library consists mainly of classes so 95% of C++ code. In order to provide better support and avoid name mangling issues I'm going to be using interfaces and factory methods to get instances of those classes rather than calling it directly. I will also use extern "C" on the factory functions ONLY to avoid name mangling.
Please bare with me I have a few questions and wasn't sure to post it as separate questions or combine it as they are related.
So here are the questions:
I will use the export/import macros on the factory functions but do I then need to add the export/import (__declspec(dllexport/import)) on the header files of all of the classes I wish to provide instances for including the base class interfaces? Or is simply exporting the factory functions enough?
I was also thinking of using smart-pointer features for automatic deallocation, good idea or let the user handle it? I was planning on using the autoptr template which is part of the standard library and available on both platforms right?
Can anyone enlighten on which calling convention I should use? I know its microsoft specific so I hope it doesn't interfere with Linux so should I leave it blank and let it be the default which I think is _thiscall or something along those lines.
I get an error for this piece of code, i'm not sure why but it is due to the extern "C":
The error is: error: declaration of C function ‘std::ostream& operator<<(std::ostream&, const MemInfo&)’ conflicts with| previous declaration ‘std::ostream& operator<<(std::ostream&, const SpeedInfo&)’ here|
error: declaration of C function ‘std::ostream& operator<<(std::ostream&, const analyzed_result&)’ conflicts with previous declaration ‘std::ostream& operator<<(std::ostream&, const MemInfo&)’ here|
... these error messages repeat for all the functions
here is the code:
//WINLIB is my macro for the dllimport/export
extern "C"{
//operator overloading for stream operation
WINLIB std::ostream& operator<<(std::ostream &st, const SpeedInfo &si);
WINLIB std::ostream& operator<<(std::ostream &st, const MemInfo &mi);
WINLIB std::ostream& operator<<(std::ostream &st, const analyzed_result&);
WINLIB std::ostream& operator<<(std::ostream &st, const ustring_set&);
WINLIB std::ostream& operator<<(std::ostream &st, const speed_map&);
WINLIB std::ostream& operator<<(std::ostream &st, const mem_map&);
WINLIB SpeedInfo operator+(SpeedInfo &si, SpeedInfo &si2);
WINLIB SpeedInfo& operator+=(SpeedInfo &si, SpeedInfo &si2);
WINLIB SpeedInfo operator-(SpeedInfo &si, SpeedInfo &si2);
WINLIB SpeedInfo& operator-=(SpeedInfo &si, SpeedInfo &si2);
WINLIB MemInfo operator+(MemInfo &mi, MemInfo &mi2);
WINLIB MemInfo& operator+=(MemInfo &mi, MemInfo &mi2);
WINLIB MemInfo operator-(MemInfo &mi, MemInfo &mi2);
WINLIB MemInfo& operator-=(MemInfo &mi, MemInfo &mi2);
}
All help greatly appreciated.