[MOAB-dev] namespace?

Jason Kraftcheck kraftche at cae.wisc.edu
Tue Mar 2 15:01:52 CST 2010


James Porter wrote:
> On Tue, 2010-03-02 at 13:57 -0600, Jason Kraftcheck wrote:
>> The disadvantages:
> [snip]
>>   3) Influences resolving of overloaded symbols by compiler.
> 
> I'd call this an advantage, though one that probably isn't particularly
> useful in our case. In practice, I doubt it'll even come up, unless we
> do something like 1) have apps with multiple versions of MOAB at once,
> or 2) create functions like MOAB::swap(MOAB::interface&,
> MOAB::interface&). 
> 

It can also trip people up.  For example, say I have some class that I
implemented:
  class Exponent {
    public: Exponent(double value);
    ...
  };

and I provide an overloaded function:
  double pow( double, const Exponent& d );

If there are no namespaces involved, then these two statements are equivalent:
  pow( 2.0, 3.14159 );
  std::pow( 2.0, 3.14150 );

If my overloaded 'pow' function is in a namespace, then for any code
anywhere in that same namespace, the following two statements are equivalent:
  pow( 2.0, 3.14159 );
  pow( 2.0, Exponent(3.14159) );

Given the choice between no type conversion in a different namespace and a
type conversion to use the function in the current namespace, the compiler
will choose the latter.

- jason


More information about the moab-dev mailing list