我有一份使用了 shared_ptr
和 STL 的 C++ 代码。一个常见的头文件如下:
#include<boost/shared_ptr.hpp>
using boost::shared_ptr; // for shared_ptr
using namespace std; // for STL
我想现在转换到c++0x,以利用语言特性,使用gcc 4.6和-std=c++0x
。然而现在有了std::shared_ptr
,会对未指定的shared_ptr
(boost::shared_ptr
vs std::shared_ptr
)造成歧义。
当转换为std::shared_ptr
时,像这样:
#include<memory>
using namespace std; // for STL; also imports std::shared_ptr
然后我遇到了与 boost::python
相关的问题,显然它只能与 boost::shared_ptr
一起使用(至少没有进一步的调整):
/usr/include/boost/python/object/make_ptr_instance.hpp:30:52: error: no matching function for call to 'get_pointer(const std::shared_ptr<Cell>&)'
我的问题是:
- 除了暂时不使用C++0x,是否有简单的解决方案来解决
boost::shared_ptr
和std::shared_ptr
之间的歧义? boost::shared_ptr
最终是否会成为std::shared_ptr
的别名?这将自动解决我的问题。
谢谢!
using namespace std
。这可能只需要对所有STL元素进行全局查找和替换即可,非常简单。 - stijnusing std::string; using std::vector;
等声明。实际上并没有使用很多std::
部分,但它们被经常使用。 - eudoxosusing std::cout; using std::string
。这增加了可读性,特别是在不太琐碎的情况下(例如using boost::phoenix::bind
或using boost:bind
,或using boost::spirit::karma::_1
等)。这样可以消除任何歧义(对编译器和程序员都是如此),而不会使实际代码混乱不堪。 - sehe