Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Namespace bug?



Hi,
	(Answer below)

> the cpp file looks like so
>
> #include "Comments.h"
>
> using namespace DOM;
>
> Comments::Comments()
> {
> }
>
> the error i get is the Comments can't be used without a type. Then I
> get told that it conflicts with a struct in AIFF.H (we include
> Carbon.h into all of our files by default. (i am working on a carbon
> project/Cocoa mixed project).
>
> However if  change my .cpp file to be....
>
> DOM::Comments::Comments()
> {
> }
>
> .. and add DOM:: to function declarations all is fine. Shouldn't the
> compiler recognize i am in a new namespace or do i have to qualify
> the declarations because of a global Comments?


That's not quite the way namespaces work.  When you declare/define
something it has to be *in* the namespace either by:
	Namespace::Class::Member(...)
or
	namespace Namespace {
		Class::Member(...) { ... }
	}

using declarations are for *looking up* references in other namespaces.
You can just write

namespace DOM {
	Comments::Comments() ...
}





David Fang

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden

References: 
 >Namespace bug? (From: Scott Andrew <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.