Questions tagged [global-namespace]
54 questions
512
votes
9 answers
What is the meaning of prepended double colon "::"?
I found this line of a code in a class which I have to modify:
::Configuration * tmpCo = m_configurationDB;//pointer to current db
and I don't know what exactly means the double colon prepended to the class name. Without that I would read:…

rmbianchi
- 6,241
- 6
- 26
- 27
43
votes
1 answer
python: NameError:global name '...‘ is not defined
in my code, I have:
class A:
def a():
......
def b():
a()
......
b()
Then the compiler will say "NameError: global name a() is not defined." If I pull all the stuffs out of the class A, it would be no problem,…

Robert
- 2,189
- 6
- 31
- 38
30
votes
4 answers
Why is including "using namespace" into a header file a bad idea in C++?
While reading from Bruce Eckel's "Thinking in C++" about namespaces, I encountered the following statement:
However you'll virtually never see a
using directive in a header file
(at least not outside of scope). The
reason is that using…

user388338
- 729
- 2
- 6
- 11
15
votes
3 answers
Is there a GCC warning for using symbols from the C library not through namespace std?
Consider the following (buggy) C++ code:
#include
#include
#include
int main() {
if (abs(-0.75) != 0.75) {
std::cout << "Math is broken!\n";
return 1;
} else {
return 0;
}
}
This…

Daniel H
- 7,223
- 2
- 26
- 41
11
votes
3 answers
How can I export from a Meteor package into my app's namespace?
I know how to write Meteor packages but I can't seem to figure out how to have all exports land in my app's namespace, as described in this presentation.
This particular package is specific to an app I'm building, and it exports only one method that…

Dan Dascalescu
- 143,271
- 52
- 317
- 404
8
votes
4 answers
Where is size_t Defined?
So I know any header from the C Compatability Headers:
Places in the global namespace each name that the corresponding cxxx header would have placed in the std namespace
I also know that these C headers were deprecated as of c++17, in favor of…

Jonathan Mee
- 37,899
- 23
- 129
- 288
8
votes
1 answer
Make a function that is declared in an autoloaded, namespaced class file, into a global function
My requirement might seem like awful practice, but none the less I would like to know if it's doable.
I'm using composer to autoload my classes. In one of the class files, I want to define a function that can be used as a shorthand within the global…

Jodes
- 14,118
- 26
- 97
- 156
7
votes
1 answer
Does ADL work for the global namespace?
Examples such as enabling outputting of std types explain how ADL can be used to "inject" a certain function/operator, depending on the type the fn/op is applied to.
I was wondering wheter ADL fully applies to the global namespace, that is, whether…

Martin Ba
- 37,187
- 33
- 183
- 337
6
votes
2 answers
How can I inject Javascript (including Prototype.js) in other sites without cluttering the global namespace?
I'm currently on a project that is a big site that uses the Prototype library, and there is already a humongous amount of Javascript code.
We're now working on a piece of code that will get "injected" into other people's sites (picture people…

Daniel Magliola
- 30,898
- 61
- 164
- 243
4
votes
1 answer
C++ Declaring function in namespace with same name as function in global namespace
I have a question regarding function declaration scopes in C++. Suppose using #include introduces a function symbol into the global namespace. According to my understanding, in principle, it should only introduce symbols into the std…

Jacques Nel
- 581
- 2
- 11
4
votes
1 answer
What does it mean to "pollute the global namespace"?
In ruby, some gems choose to "pollute the global namespace".
What does this mean?
How can I see where it's happening?
Why would a gem need to do this?
When faced with two gems that are polluting the global namespace and conflicting, what tradeoffs…

mbigras
- 7,664
- 11
- 50
- 111
4
votes
1 answer
Namespaces and free functions
I have a free function, foo, defined in a namespace N. The header for foo is in the global include search path so anyone can call it by including foo.h.
foo calls another local, free function, foo1, which is defined in foo.cpp.
// foo.h
namespace…

ksl
- 4,519
- 11
- 65
- 106
4
votes
1 answer
Doxygen/C++: Global namespace in namespace list
Can I show the global namespace in the namespace list of the documentation generated with Doxygen? I have some functions which are extern "C", they appear in the documentation of the header file that declares them, but not in the namespace list and…

Giovanni Funchal
- 8,934
- 13
- 61
- 110
4
votes
2 answers
How to force a C# root namespace throughout project files for when none is coded?
I want to force a root namespace on the contents of any .cs source files that don't have their contents wrapped in an explicit namespace. In other words I want to keep classes and other namespace-level structures out of the default…

John K
- 28,441
- 31
- 139
- 229
3
votes
2 answers
How to provide swap() for a class in the global namespace?
For a class in a namespace the proper way to provide swap() is to define a free function in that namespace (e.g. How to overload std::swap()). But what is the best practice for a class that's in the global namespace?
cppreference has an example…

Dan Stahlke
- 1,417
- 1
- 15
- 20