Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 14th, 2006, 6:42 PM   #1
iradic
Programmer
 
Join Date: Feb 2006
Posts: 36
Rep Power: 0 iradic is on a distinguished road
namespace alias?

How to use it correctly?

I have a header where I put

namespace out {
class in { /* code */ };
}

Now how do I make "namespace alias" in cpp file?

Trying:
namespace new = out::in;

doesn't work...

Error:
expected namespace-name before ';' token
unknown namespace `<declaration error>
'new' has not been declared

cc: gcc 3.4.2
os: windows 2000

Thanks

PS: Code compiles when I type full namespace names ...
iradic is offline   Reply With Quote
Old Dec 14th, 2006, 7:00 PM   #2
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 640
Rep Power: 4 Jessehk is on a distinguished road
I think it's:

namespace new = out;

As it stands, it looks like your are trying to make a namespace an alias for a class.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Dec 14th, 2006, 7:11 PM   #3
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 296
Rep Power: 4 Klarre is on a distinguished road
You use the namespaces like this:

namespace out
{
    class in {};
}

int main()
{
    out::in* instance = new out::in;
}
__________________
http://www.klarre.se
Klarre is offline   Reply With Quote
Old Dec 14th, 2006, 8:45 PM   #4
iradic
Programmer
 
Join Date: Feb 2006
Posts: 36
Rep Power: 0 iradic is on a distinguished road
Ok, thanks... I understand now...
iradic is offline   Reply With Quote
Old Dec 14th, 2006, 8:46 PM   #5
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 640
Rep Power: 4 Jessehk is on a distinguished road
He is not trying to make an instance of a class (at least, I don't think he is).

He's trying to make an alias for a namespace.

EDIT: I was just proven wrong. :p Why did you say "alias" then, iradic?
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Dec 14th, 2006, 8:49 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
In any case, you don't use 'new' as if it's a variable for assignment, it's a keyword.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Dec 14th, 2006, 9:25 PM   #7
iradic
Programmer
 
Join Date: Feb 2006
Posts: 36
Rep Power: 0 iradic is on a distinguished road
Confusion all over the place...

Jessehk correctly read my mind...

Thanks again bye..

PS: I will edit original post.
iradic is offline   Reply With Quote
Old Dec 14th, 2006, 9:28 PM   #8
iradic
Programmer
 
Join Date: Feb 2006
Posts: 36
Rep Power: 0 iradic is on a distinguished road
Edit doesn't show in my first post?
iradic is offline   Reply With Quote
Old Dec 14th, 2006, 10:00 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You can't edit after 30 minutes. Regarding editing, it's better if you ADD or EXPLAIN things in a edit (other than typos, of course), after responses have been received, so that the original meaning of the thread doesn't go south.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET Socket Class hbe02 Show Off Your Open Source Projects 1 Oct 7th, 2006 11:00 AM
import namespace hush Visual Basic .NET 3 Aug 24th, 2006 5:40 PM
C++ template and namespace question Soulstorm C++ 3 Jan 22nd, 2006 2:46 PM
Regarding namespace aniruddha_dhondge C++ 22 Sep 29th, 2005 7:38 PM
C++ namespace question kevin_cpp C++ 1 May 17th, 2005 3:28 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:36 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC