我們已經編寫了一個智能指針類,並且已經使用它,並且通過內置的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