我们已经编写了一个智能指针类,并且已经使用它,并且通过内置的Visual Studio STL实现获得了巨大成功。VS2008中带有智能指针的STLPort模糊复制构造函数类
问题是我们意识到我们的性能瓶颈在于从Linux移植的代码中STL库(STL的使用方式明显更快)。所以我试图链接到STLPort,看它是否处理我们的性能问题。
当使用STLPort 5.2.1但是我得到非常奇怪的构建错误有关的ambigous复制构造函数。我已经剥离下来到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>
]
我种停留在如何继续在这里,任何人有任何想法这个怎么回事?
在VS2010下编译得很好。尝试明确定义一个拷贝构造函数。 – ronag 2011-04-01 19:28:17
虽然不能在g ++ 4.2下编译。 – 2011-04-01 19:29:59
哦,不,不,不,不,不。重载一元运算符&'是很可怕的。 :( – 2011-04-01 19:38:56