[cs13001] on scope of the "using" statement
Mikhail Nesterenko
mikhail at cs.kent.edu
Wed Nov 20 15:02:34 EST 2013
CSI students,
On the lecture today, there was a question as to whether it was
possible to use namespaces inside functions. It turns out it is
officially possible. The rules are that statements
using namespace particularNamespace; // importing the whole namespace and
using particularNamespace::ParticularVariable; // importing a single variable
Can be used either in global scope or in any of the block (including
inside functions. The variables are imported only in the block "using"
is used. For example:
namespace myNamespace{
const int limit=5;
void myFunc(int);
}
int main(void){
using myNamespace::limit; // constant "limit" is only imported into main()
for(int i=0; i < limit; ++i)
myFunc(i);
}
Thanks,
--
Mikhail
More information about the cs13001
mailing list