- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How will you compare namespaces in Python and C++?
Namespaces in Python and C++ cannot really be compared. For example, in C++ −
// a.h namespace ns { struct A { .. }; struct B { .. }; }
If we were to do this −
#include "a.h" using ns::A;
The point of that code is to be able to write A unqualified(ie, not having to write ns::A). Now, you might consider a python equivalent as −
from a import A
But regardless of the using, the entire a.h header will still be included and compiled, so we would still be able to write ns::B, whereas in the Python version, a.B would not be visible. The other C++ version,
using namespace ns;
also doesn't have a Python analogue. It brings in all names from namespace ns throughout the entire code-base - and namespaces can be reused. For example,
#include <vector> #include <map> #include <algorithm> using namespace std; // bring in EVERYTHING
That one line is kind of equivalent to −
from vector import * from map import * from algorithm import *
at least in what it does, but then it only actually brings in what's in namespace std - which isn't necessarily everything.
- Related Articles
- How will you compare modules, classes and namespaces in Python?
- How will you explain Python namespaces in easy way?
- Namespaces and Scoping in Python
- Namespaces and Scope in Python
- How to define namespaces in C#?
- How to use namespaces in C++?
- How do you compare Python objects with .NET objects?
- How will you explain Python Operator Overloading?
- How to generate XML documents with namespaces in Python?
- How you will create your first program in Python?
- How will you handle alerts in Selenium with python?
- What are namespaces in C#?
- What is difference between builtin and globals namespaces in Python?
- What are nested namespaces in C#?
- Can namespaces be nested in C++?
