Re: just C++ in xcode
Re: just C++ in xcode
- Subject: Re: just C++ in xcode
- From: Andreas Grosam <email@hidden>
- Date: Thu, 29 Sep 2005 16:26:53 +0200
On 29.09.2005, at 15: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?
No, it would save you typing the fully qualified name, but only where it is applicable, and would not be illegal code.
This is just illegal code (as explained previously):
#include <header.h>
using namespace n;
x = 1; // error: illegal definition without a type.
// This is not a reference to n::x!
// A relaxed compiler would probably introduce x of type int
// in global space as if it were written:
// int x = 1;
Here it works as you expect:
#include <iostream>
#include <n.h>
using namespace std;
using namespace n;
int x = 1; // declaration-definition of x in global space
static void func()
{
x = 10; // that's an assignment to n::x
cout << ::x << endl; // prints ::x "1"
cout << x << endl; // prints n::x "10"
}
without "using":
#include <iostream>
#include <n.h>
int x = 1;
void func();
static void func()
{
n::x = 10;
std::cout << ::x << std::endl; // prints ::x "1"
std::cout << n::x << std::endl; // prints n::x "10"
}
Andreas
Chris
On Thu, 29 Sep 2005 15:07:48 +0200, Andreas Grosam wrote
> On 29.09.2005, at 05:53, Marshall Clow wrote:
>
>
> 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