ibanja
asked on
What's the best way to not keep typing in long namespaces before functions and variables?
What is the best way to avoid the long namespaces such as lucene::index::IndexWriter ?
Is it correct to just use the following:
using namespace lucene::index;
IndexWriter writer = new IndexWriter(indexDir, analyzer, true);
then change to another namespace:
using namespace lucene::analysis;
more code ...
using namespace std;
cout << "Hi";
Thanks,
ibanja
Is it correct to just use the following:
using namespace lucene::index;
IndexWriter writer = new IndexWriter(indexDir, analyzer, true);
then change to another namespace:
using namespace lucene::analysis;
more code ...
using namespace std;
cout << "Hi";
Thanks,
ibanja
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks,
So if I understand correctly - multiple namespaces can be in use and:
using namespace lucene::index;
using namespace lucene::analysis;
using namespace std;
code ...
code ...
code ...
is the same as:
using namespace lucene::index;
code ...
using namespace lucene::analysis;
code ...
using namespace std;
code ...
since setting one name space doesn't nullify another namespace.
So if I understand correctly - multiple namespaces can be in use and:
using namespace lucene::index;
using namespace lucene::analysis;
using namespace std;
code ...
code ...
code ...
is the same as:
using namespace lucene::index;
code ...
using namespace lucene::analysis;
code ...
using namespace std;
code ...
since setting one name space doesn't nullify another namespace.
Yes, but it is common practice to put all of you "using" statements together at the top of the relevant file.
You can, but you are risking conflicts if these namespaces contain types that are named identically.
ASKER
Thanks,
I think I've got it.
I think I've got it.
> Is it correct to just use the following:
> using namespace lucene::index;
Only in your *.cpp source file.
You should avoid doing this in the headers, and instead use fully qualified names.
David Maisonave (Axter)
Cheers!