> For the complete documentation index, see [llms.txt](https://wiki.purduesigbots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.purduesigbots.com/software/c++-basics-for-vex-robotics/namespaces.md).

# Namespaces (::)

namespace::feature()

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.

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.**

PROS uses namespaces extensively with their `pros` namespace, while VEXCode uses their `vex` namespace accordingly.

### 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.

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).**

#### Teams Contributed to this Article:

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
