John wrote:
I am using two large libraries which both have an implementation
of a "matrix" class. I have the source code for both.
I need to use them in the same project and when I try to compile
I get a double declaration conflict. I tried to wrap the smaller
library into a namespace but its a nightmare. Is there anyway
I could solve this problem without giving up on one of the libraries?
Thanks,
--j
This is exactly the type of problem that C++ namespaces should be able
to handle. It's unclear what what part of the process turned into a
nightmare, or even how the name conflict manifests itself in the first
place. Does it cause a compiler error or just a linker error? Are both
matrix classes used in the source files, or is it an include file
problem? If both matrix classes are in use, does any single source file
use both?
Ideally, it should be possible to place both the interface and the
implementation of one of the libraries into a namespace. Just place a
"namespace MathLib { " at the top of the header and the source file and
a closing } at the end of both files (of course the namespace's name
doesn't have to be "Mathlib", in fact it's possible to alias
namespaces, so more than one name is possible). And although header
files should not have "using" directives that import names into the
global namespace; there is no problem importing global (or names from
other namespaces) into a namespace. Doing so may resolve difficulties
caused by having placed the interface into a namespace.
Greg
[ See
http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]