我们编写了一个智能指针类,并通过内置的 Visual Studio STL 实现成功地使用它。
问题是我们已经意识到我们的性能瓶颈存在于从 Linux 移植的代码中的 STL 库中(其中 STL 比我们使用它的方式快得多)。所以我试图在 STLPort 中链接,看看它是否能解决我们的性能问题。
但是,当使用 STLPort 5.2.1 时,我会遇到与模棱两可的复制构造函数相关的非常奇怪的构建错误。我把它精简为一个 50 行的 C++ 程序
#include "stdafx.h"
#include <set>
using namespace std;
template<class T>
class CRefCountPtr
{
public:
CRefCountPtr(T* pT) : m_T(pT)
{
}
T** operator&()
{
return &m_T;
}
operator T*() const
{
return (T*)m_T;
}
bool operator< (T* pT) const
{
return m_T < pT;
}
T* m_T;
};
class Example
{
int example;
};
int _tmain(int argc, _TCHAR* argv[])
{
set< CRefCountPtr<Example> > blah;
Example ex;
blah.insert(&ex);
return 0;
}
我从 VS2008SP1 得到的错误是
stlport\stl\_tree.h(318) : error C2782: 'void stlp_std::_Copy_Construct(_Tp *,const _Tp &)' : template parameter '_Tp' is ambiguous
stlport\stl\_construct.h(130) : see declaration of 'stlp_std::_Copy_Construct'
could be 'CRefCountPtr<T>'
with
[
T=Example
]
or 'Example *'
.....
stlport_example.cpp(43) : see reference to class template instantiation 'stlp_std::set<_Key>' being compiled
with
[
_Key=CRefCountPtr<Example>
]
我有点卡在如何在这里进行,有人知道这是怎么回事吗?