Florian Lindner <[email protected]> writes: > Hello, > > This may be rather a C/C++ question, but ... > > I encapsulate some petsc functions into c++ classes. Since I don't want > to pull all petsc symbols into the global namespace for anyone using my > classes I try to put petsc into it's own namespace: > > Header petsc.h:
Note that there is already a petsc.h in the PETSc distribution. It is
different from yours.
> namespace petsc {
> #include "petscmat.h"
> }
>
> class Vector {
> petsc::Vec vector;
> }
>
>
> Implementation petsc.cpp:
>
> #include "petsc.h"
>
> namespace petsc {
> #include "petscviewer.h"
> }
>
> using namespace petsc;
>
>
> User:
>
> #include "petsc.h"
> #include <petscksp.h> // if the user wants he can import parts of petsc
> of course
>
>
> But this gives a massive amount of error messsages like:
>
> mpic++ -o petsc.o -c -O0 -g3 -Wall
> -I/home/florian/software/petsc/include
> -I/home/florian/software/petsc/arch-linux2-c-debug/include petsc.cpp
> mpic++ -o prbf.o -c -O0 -g3 -Wall -I/home/florian/software/petsc/include
> -I/home/florian/software/petsc/arch-linux2-c-debug/include prbf.cpp
> In file included from
> /home/florian/software/petsc/include/petscksp.h:6:0,
> from prbf.cpp:9:
> /home/florian/software/petsc/include/petscpc.h:9:14: error:
> 'PetscErrorCode' does not name a type
> PETSC_EXTERN PetscErrorCode PCInitializePackage(void);
What do you expect when you put some things in the namespace and include
dependencies outside the namespace?
namespaces don't play well with macros (including header guards). I
don't think what you are attempting is a good use of time, but if you do
it, I would recommend creating a public interface that does not include
any PETSc headers, thus completely hiding the PETSc interface.
pgpSBLY8Tmein.pgp
Description: PGP signature
