Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function namespacing issues in D

Tags:

d

Say I have a class Foo with a member function bar(). I also have a completely unrelated function which happens to be named bar() as well.

class Foo {
    /* ... */
    void bar() {
        /* ... */
    }
}

void bar() { /* ... */ }

It seems that any call to bar() from within Foo defaults to the member function.

How do I call the non-member function from inside Foo?

like image 915
Shriken Avatar asked Mar 11 '15 14:03

Shriken


People also ask

What is the main purpose of Namespacing in PHP?

In the PHP world, namespaces are designed to solve two problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions: Name collisions between code you create, and internal PHP classes/functions/constants or third-party classes/functions/constants.

What is Namespacing in JavaScript?

JavaScript Namespaces: Namespace refers to the programming paradigm of providing scope to the identifiers (names of types, functions, variables, etc) to prevent collisions between them. For instance, the same variable name might be required in a program in different contexts.

What is Namespacing in Python?

Namespaces in Python. A namespace is a collection of currently defined symbolic names along with information about the object that each name references. You can think of a namespace as a dictionary in which the keys are the object names and the values are the objects themselves.

What is namespace and its types?

A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.


1 Answers

Like this:

.bar();

The leading . will force the compiler to look at the module-level scope.

You can also use the fully-qualified name: module_name.bar(), where module_name is the name of the module (by default, the filename without the .d extension).

like image 54
Vladimir Panteleev Avatar answered Oct 21 '22 05:10

Vladimir Panteleev