IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Parker on January 10, 2006, 02:00:20 PM

Title: What is the importance of namespaces?
Post by: Parker on January 10, 2006, 02:00:20 PM
I know that C++ and C# support namespaces and java calls them packages I think, if they're the same thing. But I was wondering, what are they and what's the point? Are they just an alias for a class, or is there more?
Title: Re: What is the importance of namespaces?
Post by: Parker on January 10, 2006, 02:05:24 PM
And for anyone that knows a lot about this stuff, reinterpret_cast, static_cast, const_cast, dynamic_cast? Sorry, it's just I'm not used to what those do and I can't imagine how you can cast in that many different ways.
Title: Re: What is the importance of namespaces?
Post by: Zen on January 10, 2006, 04:44:08 PM
Namespaces allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in "sub-scopes", each one with its own name.

For example.

#include <iostream>
using namespace std;

namespace first
{
  int var = 5;
}

namespace second
{
  double var = 3.1416;
}

int main () {
  cout << first::var << endl;
  cout << second::var << endl;
  return 0;
}


As for the rest Parker, i have no idea.

Lewis
Title: Re: What is the importance of namespaces?
Post by: Parker on January 10, 2006, 05:19:32 PM
That's interesting, you can do the same by using static variables in classes. Maybe it's just one of those extra features they thought would be a good idea.
Title: Re: What is the importance of namespaces?
Post by: Ionic Wind Support Team on January 10, 2006, 06:02:08 PM
The multiple forms of casting are needed with C++ since you can derive an object from more than one base class at once. 

class Complex: base1, base2
{
}

If you had a pointer to the class at the level of base1, which is common when using lists, and you want to access a method in base2 you need to reinterpret the case.  Which is only safe ofcourse if all objects contained in the list derive from the same two base classes.

Paul.