Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error declaring "using namespace" with a nested namespace ("namespace xxx::yyy not allowed in using-declaration")

Tags:

c++

namespaces

When I write C++ code, I try to use a using <X> to keep from polluting too much. In Crypto++, it gives me problem in one case. The case is the ASN1 namespace within the CryptoPP namespace (it only shows up in one place).

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

I can use, for example, secp256r1 curve with:

CryptoPP::ASN1::secp256r1();

However, I have not figured out a way to declare it with using. When I try:

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

It eventually leads to error: namespace ‘CryptoPP::ASN1’ not allowed in using-declaration, and then error: ‘ASN1’ has not been declared at the following (I tried them both):

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

How does one use a using statement when there is more than one namespace?


$ g++ -version
i686-apple-darwin11-llvm-g++-4.2
like image 514
jww Avatar asked Dec 22 '12 02:12

jww


1 Answers

Just say:

using namespace CryptoPP::ASN1;
like image 86
Charles Salvia Avatar answered Oct 17 '22 05:10

Charles Salvia