Topic: namespace, using and ::
Author: rich_paul@bigfoot.com
Date: 1998/04/12 Raw View
In article <hinnant-0804980919110001@port32.lightlink.com>,
hinnant@_anti-spam_metrowerks.com (Howard Hinnant) wrote:
How 'bout this?
// this, of course, is in <string>
namespace std {
typedef basic_string<char> string;
typedef basic_stringstream<char> stringstream;
};
typedef basic_string<char,i_char_traits> string;
typedef basic_stringstream<char,i_char_traits> stringstream;
using namespace std;
using ::string;
using ::stringstream;
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Hankel O'Fung" <hkfung@ust.hk>
Date: 1998/04/14 Raw View
Dear all,
rich_paul@bigfoot.com wrote:
> How 'bout this?
>
> 01 // this, of course, is in <string>
> 02 namespace std {
> 03 typedef basic_string<char> string;
> 04 typedef basic_stringstream<char> stringstream;
> 05 };
>
> 06 typedef basic_string<char,i_char_traits> string;
> 07 typedef basic_stringstream<char,i_char_traits> stringstream;
>
> 08 using namespace std;
> 09 using ::string;
> 10 using ::stringstream;
As I'm quite novice to C++, I can't answer your question. Hope someone can
solve our doubt. However, I wish to make a guess. According to Stroustrup's
"The C++ Programming Language" (3/e, p.847),
"... using-declaration adds a name to a local scope. A using-directive does
not; it simply renders names accessible in the scope in which they were
declared."
So, line 08 has no conflicts with lines 09 and 10. It seems that whether the
above codes are correct relies on the question whether line 06 (or resp. 07)
clashes with line 09 (resp. 10) or not.
Is the following correct? In line 11 we define the entity/name INT. In line
12, is INT considered as being redeclared? I think (= guess) the answer is
affirmative if "using N::M" really ADDS a name M to the current scope. In
other words, I think neither rich_paul's code nor mine can be compiled.
11 typedef int INT;
12 using ::INT;
Hankel
--
Dept of Ind Engg & Engg Mgt (IEEM)
HKUST, Clear Water Bay, Kowloon
Hong Kong
tel (852) 2358 7103 fax (852) 2358 0062
http://home.ust.hk/~hkfung
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1998/04/08 Raw View
Should the following code work?
namespace A
{
int x;
}
namespace B
{
using namespace A;
}
int main()
{
B::x=5;
}
What about the following?
namespace A
{
int x;
}
namespace B
{
using A::x;
}
int main()
{
B::x=5;
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: hinnant@_anti-spam_metrowerks.com (Howard Hinnant)
Date: 1998/04/08 Raw View
In article <352B3542.1D759E88@physik.tu-muenchen.de>, Christopher Eltschka
<celtschk@physik.tu-muenchen.de> wrote:
> Should the following code work?
>
> namespace A
> {
> int x;
> }
>
> namespace B
> {
> using namespace A;
> }
>
> int main()
> {
> B::x=5;
> }
Yes.
> What about the following?
>
> namespace A
> {
> int x;
> }
>
> namespace B
> {
> using A::x;
> }
>
> int main()
> {
> B::x=5;
> }
Yes.
-Howard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]