Namespace Injection and std::size_t

E

earthwormgaz

I am trying to add the headers for a library I am using to a namespace
to avert issues with name clashes.

namespace Lib
{
#include <Lib/SomeFile.h>
};

I am finding though that statements to the following effect in that
code are then broken ...

using std::size_t;

The compiler complains that it doesn't know about size_t, I presume
that is because it only knows about Lib::std::size_t.

How can I get out of this?
 
O

ondra.holub

Maybe could help

namespace Lib
{
using namespace std;

#include <Lib/SomeFile.h>
}
 
P

Pete Becker

earthwormgaz said:
I am trying to add the headers for a library I am using to a namespace
to avert issues with name clashes.

namespace Lib
{
#include <Lib/SomeFile.h>
};

I am finding though that statements to the following effect in that
code are then broken ...

using std::size_t;

The compiler complains that it doesn't know about size_t, I presume
that is because it only knows about Lib::std::size_t.

Most likely, SomeFile.h #includes a header from the standard library. If
you #include a standard library header inside a namespace the behavior
of the program is undefined, precisely because of this sort of problem.
But even if you dodge around the problems this causes for the standard
library, there's a good chance that the other library you're using won't
work right, because it wasn't compiled with its names inside your namespace.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top