【发布时间】:2012-12-22 02:14:39
【问题描述】:
当我编写 C++ 代码时,我尝试使用 using <X> 来避免过多的污染。在 Crypto++ 中,它在一种情况下给我带来了问题。案例是 CryptoPP 命名空间中的 ASN1 命名空间(它只出现在一个地方)。
这是 Crypto++ 中的声明:http://www.cryptopp.com/docs/ref/oids_8h_source.html。
例如,我可以使用 secp256r1 曲线:
CryptoPP::ASN1::secp256r1();
但是,我还没有想出一种使用 using 来声明它的方法。当我尝试时:
#include <cryptopp/asn.h>
#include <cryptopp/oids.h>
using CryptoPP::ASN1;
它最终导致error: namespace ‘CryptoPP::ASN1’ not allowed in using-declaration,然后是error: ‘ASN1’ has not been declared(我都试过了):
ECIES<ECP>::Decryptor d1(prng, secp256r1());
ECIES<ECP>::Decryptor d2(prng, ASN1::secp256r1());
当有多个命名空间时,如何使用using 语句?
$ g++ -version
i686-apple-darwin11-llvm-g++-4.2
【问题讨论】:
-
using namespace CryptoPP::ASN1;
标签: c++ namespaces