Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   namespace alias? (http://www.programmingforums.org/showthread.php?t=12185)

iradic Dec 14th, 2006 7:42 PM

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 ...

Jessehk Dec 14th, 2006 8:00 PM

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.

Klarre Dec 14th, 2006 8:11 PM

You use the namespaces like this:

:

namespace out
{
    class in {};
}

int main()
{
    out::in* instance = new out::in;
}


iradic Dec 14th, 2006 9:45 PM

Ok, thanks... I understand now...

Jessehk Dec 14th, 2006 9:46 PM

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?

DaWei Dec 14th, 2006 9:49 PM

In any case, you don't use 'new' as if it's a variable for assignment, it's a keyword.

iradic Dec 14th, 2006 10:25 PM

Confusion all over the place... :)

Jessehk correctly read my mind...

Thanks again bye..

PS: I will edit original post.

iradic Dec 14th, 2006 10:28 PM

Edit doesn't show in my first post?

DaWei Dec 14th, 2006 11:00 PM

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.


All times are GMT -5. The time now is 1:33 AM.

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