On the namespaces of several common languages (Namespace) _c language

Source: Internet
Author: User

namespaces provide a way to logically organize classes to prevent naming conflicts.

Several common languages

C++

Namespaces can be nested

Nested namespaces are namespaces that are defined in other namespaces. A nested namespace is a nested scope, and the name of the inner namespace declaration hides the member with the same name as the outer namespace declaration:

int x =; 
namespace Outer { 
 int x = ten; 
 namespace inner { 
  int z = x; 
 } 
} 
 
int main () 
{ 
 std::cout << outer::inner::z;//output: 
 0; 
} 

C#

Nested namespaces

namespace declaration, where the namespaces are declared with the "." Separated.

For example:

Namespace N1. N2
{
class A {}
class B {}
}

is semantically equivalent to

Namespace N1
{
namespace N2
{
class A {
}}} 

Java

Package Cn.org.web3d.x3dpad

Namespaces in Java mean that you can guarantee the absolute uniqueness of your project as long as you have a single top-level domain.

Objective-c

All class names in the OBJECTIVE-C application must be globally unique. Naming has always been Objective-c's mishap, compared with those of elegant language. Apple has officially suggested that the two-letter prefix class name is for the official library and framework, and that as a third-party developer, the official recommendation is to use 3 or more letters as prefixes to name our class.

Php

Namespace vendor\package\ ...

It emphasizes that the first level of vendor should be the uniqueness of the logo, meaning that you have to have a {vendor}.com top-level domain name, you can guarantee the absolute uniqueness of your project. For example, when I think about it, I immediately register a meanir.com domain name to defend myself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.