读书人

急求高手解答解决方法

发布时间: 2013-11-15 22:28:15 作者: rapoo

急求高手解答
这只是为了解决问题模拟出来的代码,但效果一样的。
#include <vector>
using namespace std;
struct CSWFIndex
{
typedef void (*DECONS)(void *);
CSWFIndex() : pDecon(0) {}
~CSWFIndex() {Reset();}

void Reset()
{
if (pDecon && pDecon != (void *)1) (*pDecon)(pvBuff);
pDecon = 0;
}
int IsEnumDone()
{
return pDecon == 0;
}

void *pvBuff[3];
DECONS pDecon;
};

template <typename _Type>
static void SWF_DeconstructAgent(_Type * p)
{
p->_Type::~_Type();
}

template<typename _Type>
inline _Type& SWF_Index_Init(CSWFIndex& idx, const _Type& val)
{
if (idx.pDecon == 0)
{
idx.pDecon = (CSWFIndex::DECONS)&SWF_DeconstructAgent<_Type>;
new (idx.pvBuff) _Type(val);
}

return *((_Type *)idx.pvBuff);
}




int main()
{
vector<int> intVector;
intVector.push_back(1);

CSWFIndex idx;

vector<int>::const_iterator it = SWF_Index_Init(idx, intVector.begin());
}

编译报错:[root@localhost vmshare]# g++ 1.cpp
1.cpp: In function ‘_Type& SWF_Index_Init(CSWFIndex&, const _Type&) [with _Type = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >]’:
1.cpp:51: instantiated from here
1.cpp:34: error: address of overloaded function with no contextual type information

求哪位大侠解决一下,万分感激。。 linux?c++?模板
[解决办法]


idx.pDecon = (CSWFIndex::DECONS)&SWF_DeconstructAgent<_Type>;

改为:

void (*pf)(_Type *) = &SWF_DeconstructAgent<_Type>;
idx.pDecon = (CSWFIndex::DECONS)pf;

读书人网 >C++

热点推荐