• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: just C++ in xcode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: just C++ in xcode


  • Subject: Re: just C++ in xcode
  • From: Markian Hlynka <email@hidden>
  • Date: Thu, 29 Sep 2005 12:14:42 -0600


On Sep 29, 2005, at 7:30, Christopher Nagel wrote:

Wow, that was fun reading! So, unlike C#, C++'s "using" directive does not save you typing the FQEN (fully-qualified entity name)? One would have thought that "using namespace n" meant that any reference to x would translate to n::x , no? If not, I wonder what does 'using' buy you?

I'm a little unconvinced too... I mean, what is Andreas saying... that int x; doesn't define a variable? So what? It declares it in the namespace, so why can't we define it elsewhere? I'm not sure I understand this point. Otherwise, as Chris says, what's the point of "using namespace"?


According to Josuttis in "The C++ Standard Library", "A using directive makes all names of a namespace availble, because they would have been declared outside their namespace. However, the usual name conflicts may arise.... The compiler will report an ambiguity [if there is a name collision in global scope] and the user uses the name without qualification." Note first that he said "declared", not defined. Note second that in his example (pg 17) he has:

namespace josuttis {
    class File;
    void blah(const File&);
    ...
}

Neither of these is a definition, they are just declarations, so how is this different? He goes on to say that you should never use a using directive in header files, modules, libraries, etc, when the context in unclear, because it might change the scope of identifiers of a namespace. Ie, if your .h file says using namespace foo, which has a member x. You include foo in some file that creates a namespace bar, you may have just inadvertently changed the scope of bar::x. You wanted bar::x but the header used foo, so you actually got foo::x. Or is it foo::bar::x? I'm not sure. Correct me if I'm wrong.

But either way, I still don't quite understand why Joe's code is wrong.

Markian
> Maybe this is a C++ question not having to do with
> xcode, but I'm desparate...
>
> If I have a named namespace in foo1.h:
...

> namespace n {
> int x;
> };
> using namespace n;
> x = 1;
>
> The statement above
> x = 1;
> actually introduces a new variable in global space which does not have a type.

_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >just C++ in xcode (From: Joe Kurtz <email@hidden>)
 >Re: just C++ in xcode (From: Marshall Clow <email@hidden>)
 >Re: just C++ in xcode (From: Andreas Grosam <email@hidden>)
 >Re: just C++ in xcode (From: "Christopher Nagel" <email@hidden>)

  • Prev by Date: failed to load custom data formatter plugin
  • Next by Date: Re: Finder won't open Xcode projects
  • Previous by thread: Re: just C++ in xcode
  • Next by thread: Re: C with C++ in xcode
  • Index(es):
    • Date
    • Thread