# Namespaces (::)

Namespaces are an easy way to avoid name conflicts in large projects by grouping related code under a name. They help keep your code organized and prevent different parts of the program from interfering with each other. They can look like `namespace::feature` and might be slightly confusing to newer users.&#x20;

Here's a simple example of how to use namespaces in C++:

```cpp
#include <iostream>

// Define a namespace called 'First'
namespace First {
    // Inside this namespace, we define a function 'display'
    void display() {
        std::cout << "This is the First namespace." << std::endl;
    }
}

// Define another namespace called 'Second'
namespace Second {
    // Inside this namespace, we define another function 'display'
    void display() {
        std::cout << "This is the Second namespace." << std::endl;
    }
}

int main() {
    // Call the 'display' function from the 'First' namespace
    First::display();
    
    // Call the 'display' function from the 'Second' namespace
    Second::display();
    
    return 0;
}
```

In this example, both `First` and `Second` namespaces have their own `display` function. By specifying the namespace (using `First::` or `Second::`), you avoid any confusion between the two functions. **This is especially helpful in larger projects where different parts of the code might use the same function names.**&#x20;

PROS uses namespaces extensively with their `pros` namespace, while VEXCode uses their `vex` namespace accordingly.&#x20;

### Didn't Understand What was Written Above?

Ok let's use a non-code example:

Your friend asks for you to get a burger. However, you don't know what sort of burger they want.&#x20;

They could be asking for a burger from Burger King, McDonalds, or some other fast food restuarant!

If we were to treat the menus of these fast food restuarants as namespaces, and the burgers as functions or classes, they'd look something like this in C++:

```cpp
McDonalds::burger

Burger_King::burger
```

**Now, we can have foods (objects or functions) such as a "burger" from different resturaunts (namespaces).** &#x20;

#### Teams Contributed to this Article:

* [BLRS](https://purduesigbots.com/) (Purdue SIGBots)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.purduesigbots.com/software/c++-basics-for-vex-robotics/namespaces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
