Declaration error "using namespace" with nested namespace ("namespace xxx :: yyy is not allowed in the use-declaration")

When I write C ++ code, I try to use using <X> so as not to pollute too much. In Crypto ++, this gives me a problem in one case. The case is the ASN1 namespace in the CryptoPP namespace (it appears in only one place).

Here's the ad in Crypto ++: http://www.cryptopp.com/docs/ref/oids_8h_source.html .

I can use, for example, the secp256r1 curve with:

 CryptoPP::ASN1::secp256r1(); 

However, I did not understand the way to declare it using. When I try:

 #include <cryptopp/asn.h> #include <cryptopp/oids.h> using CryptoPP::ASN1; 

As a result, it leads to error: namespace 'CryptoPP::ASN1' not allowed in using-declaration , and then error: 'ASN1' has not been declared in the following (I tried both of them):

 ECIES<ECP>::Decryptor d1(prng, secp256r1()); ECIES<ECP>::Decryptor d2(prng, ASN1::secp256r1()); 

How to use using statement when more than one namespace exists?


 $ g++ -version i686-apple-darwin11-llvm-g++-4.2 
+4
source share
4 answers

Just say:

 using namespace CryptoPP::ASN1; 
+12
source

ASN1 is a namespace. Try:

 using namespace CryptoPP::ASN1; 
+4
source

Try

 using CryptoPP::ASN1::secp256r1; 

... then calling secp256r without qualification. This avoids the use of a namespace, which some are unhappy with.

+2
source

Other answers recommend using namespace CryptoPP::ASN1; but this is not what you wanted (presumably) as it imports the entire contents of the ASN1 namespace into your scope.

I assume you wanted to do this:

 namespace ASN1 = CryptoPP::ASN1; 

This will allow you to use, for example, ASN1::secp256r1() in your area.

+1
source

All Articles