Free functions versus member functions

Bill Baxter dnewsgroup at billbaxter.com
Thu Oct 11 17:13:51 PDT 2007


Jari-Matti Mäkelä wrote:
> Bill Baxter wrote:
> 
>> Another difference is that in C++ you have to *explicitly* say you want
>> to bring members of a namespace into your current namespace with a
>> "using" directive.
>>
>> In contrast, D's imports throw all the symbols into the local namespace
>> by default.  You have to do something extra to prevent it ("static
>> import" instead of import).
> 
> I haven't been using C++ lately, but isn't 'using namespace' similar to D
> import - it imports all symbols from the namespace. Explicit syntax is
> nameSpace::symbol IIRC.
> 
>> "Using" is also a nice tool for manipulating visibility of namespaces.
>> D doesn't have anything quite like it.   You can say at the function
>> level for instance "using SomeNamespace" and then you can use things
>> from that namespace unqualified, but just to the end of that function.
>> There's also a renamed using -- something like "using SNS =
>> SomeNamespace;" I think.
> 
> Well isn't this what has been proposed for D already, i.e. imports inside
> non-module level scopes.

Maybe, assuming the imports could be repeats of already imported 
modules.   But anyway, proposed and implemented are very different 
things.  People have also proposed that D compilers should be able 
compile C++ code directly.

--bb



More information about the Digitalmars-d mailing list