By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,337 Members | 1,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,337 IT Pros & Developers. It's quick & easy.

Namespace Injection and std::size_t

P: n/a
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?

Nov 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Maybe could help

namespace Lib
{
using namespace std;

#include <Lib/SomeFile.h>
}

Nov 16 '06 #2

P: n/a
earthwormgaz wrote:
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)
Nov 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.