Re: UN-using a namespace?
Igor Tandetnik wrote:
Alex Blekhman <xfkt@oohay.moc> wrote:
It rises another question. Whether is
it possible at all to encapsulate 3rd party code within a
namespace.
Yes, if you have full source and can recompile. No if you only have
binaries.
That's not entirely true, I believe. It is still possible to wrap
the offending library in a DLL and use that. Duplicate the headers,
implement the function by calling global functions with the same
name, put your wrapping functions in the namespace, and then import
it instead of the 3rd party one. Just a lot of typing...
------------------ offending_library.h
int time(void*);
------------------------------------
------------------ wrapper.h
namespace NAUGHTY {
int time(void*);
}
------------------ wrapper.cpp
#include <offending_library.h>
#include <wrapper.h>
int NAUGHTY::time(void* p) { return ::time(p); }
------------------------------
------------------ your code.cpp
#include <wrapper.h>
...
int k = NAUGHTY::time(0); // or whatever
------------------------------------------------------
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask