Link to home
Start Free TrialLog in
Avatar of ibanja
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
Avatar of Axter
Axter
Flag of United States of America image

Hi ibanja,
> 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!
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ibanja
ibanja

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.
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.
Avatar of ibanja

ASKER

Thanks,

I think I've got it.