[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

namespace and #include

Hua.watson

9/24/2008 11:35:00 AM

I want to add some declaration intio my namespace. But I do not have
the right to modify proto header files.
So I try


namespace mynamespace{
#include "a.h"
#include "b.h"
}

This is not a good style. But it even cannot work..... functions in
a.h has NOT been put into mynamespace....
4 Answers

puzzlecracker

9/24/2008 1:17:00 PM

0

On Sep 24, 7:35 am, Hua.wat...@gmail.com wrote:
> I want to add some declaration intio my namespace. But I do not have
> the right to modify proto header files.
> So I try
>
> namespace mynamespace{
> #include "a.h"
> #include "b.h"
>
> }
>
> This is not a good style. But it even cannot work..... functions in
> a.h has NOT been put into mynamespace....

This should help you solve your problems with migrating to namespace:
http://www.gotw.ca/go...

Barry

9/24/2008 2:00:00 PM

0

On Sep 24, 7:35 pm, Hua.wat...@gmail.com wrote:
> I want to add some declaration intio my namespace. But I do not have
> the right to modify proto header files.
> So I try
>
> namespace mynamespace{
> #include "a.h"
> #include "b.h"
>
> }
>
> This is not a good style. But it even cannot work..... functions in
> a.h has NOT been put into mynamespace....

you also need to put the definition into your new namespace.

I guess you forgot to wrap your cxx files with your namespace.
suppose you have a.cpp corresponding to a.h, whereas b.cpp for a.h

use wrappers like a_wrap.cpp as following, and do remember to have
header
inclusion guard.

suppose A_H_INCLUDED for a.h

#include "a.h" // A_H_INCLUDED is define here

namespace mynamespace {
#include "a.cpp" // preprocesser #include "a.h" in a.cpp will be
discarded
}

exclude a.cpp in your project. while a_wrap.cpp is included

HTH.

--
Best Regards
Barry

Barry

9/24/2008 2:20:00 PM

0

On Sep 24, 7:35 pm, Hua.wat...@gmail.com wrote:
> I want to add some declaration intio my namespace. But I do not have
> the right to modify proto header files.
> So I try
>
> namespace mynamespace{
> #include "a.h"
> #include "b.h"
>
> }
>
> This is not a good style. But it even cannot work..... functions in
> a.h has NOT been put into mynamespace....

you need to put the definition into your namespace

I guess you forgot to wrap your cxx files into you namespace
suppose you have a.cpp for a.h

remember to have header inclusion guard
suppose A_H_INCLUDED for a.h

so write your a_wrap.cpp like this:

#include "a.h" // A_H_INCLUDED is defined

namespace mynamespace {
#include "a.cpp" // a.h in a.cpp will be discarded
}


HTH.

--
Best Regards
Barry

Hua.watson

9/25/2008 2:13:00 AM

0

On 9?24?, ??10?20?, Barry <dhb2...@gmail.com> wrote:
> On Sep 24, 7:35 pm, Hua.wat...@gmail.com wrote:
>
> > I want to add some declaration intio my namespace. But I do not have
> > the right to modify proto header files.
> > So I try
>
> > namespace mynamespace{
> > #include "a.h"
> > #include "b.h"
>
> > }
>
> > This is not a good style. But it even cannot work..... functions in
> > a.h has NOT been put into mynamespace....
>
> you need to put the definition into your namespace
>
> I guess you forgot to wrap your cxx files into you namespace
> suppose you have a.cpp for a.h
>
> remember to have header inclusion guard
> suppose A_H_INCLUDED for a.h
>
> so write your a_wrap.cpp like this:
>
> #include "a.h" // A_H_INCLUDED is defined
>
> namespace mynamespace {
> #include "a.cpp" // a.h in a.cpp will be discarded
>
> }
>
> HTH.
>
> --
> Best Regards
> Barry
Thanks, my code is like:

In global.h:
typedef int int32_t;
enum{ENUM_A};

In someone.h:
enum{ENUM_A};

In my.h:
namespace myspace{
#include "a.h"
}

In my.cpp
#include "global.h"
#include "someone.h"

myspace::int32_t ........

Then compiler tell me 2 error
1. ENUM_A conflict
2. int32_t is not in namespace myspace

In fact, I need include both global.h and someone.h to use some
functions, however, they defined some same unnamed enum. Now I have to
use 2 cpp file.....

Thanks