namespace CounterNameSpace {
int upperbound;
int lowerbound;
using namespace NS;//Error
}
namespace NS {
int i;
}
// ...
namespace NS {
int j;
}
In the above case it shows an error . error C2871: 'NS' : a namespace with this name does not exist I know if i define NS before counternamespace problem will be solved . But just want to know whether any thing like forward declaration of namespace exist in c++ or not .So that the above problem will be resolved without defining NS before counternamespace . please help .
There is no forward declaration of namespace. You can forward declare a function.
In computer programming, a forward declaration is a declaration of an identifier (denoting an entity such as a type, a variable, a constant, or a function) for which the programmer has not yet given a complete definition.
In C++, Forward declarations are usually used for Classes. In this, the class is pre-defined before its use so that it can be called and used by other classes that are defined before this. Example: // Forward Declaration class A class A; // Definition of class A class A{ // Body };
Typically, you declare a namespace in a header file. If your function implementations are in a separate file, then qualify the function names, as in this example. A namespace can be declared in multiple blocks in a single file, and in multiple files.
Nothing says a namespace needs all of its contents right away:
namespace NS {}
namespace CounterNameSpace {
int upperbound;
int lowerbound;
using namespace NS;
}
namespace NS {
int i;
}
However, this might not do what you want. You still won't be able to use any of the types in that namespace until you've declared them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With