我在其他论坛上问过,但没有人回答:SI 不断得到:
6 个重载中没有一个可以转换所有参数。
我只在视觉工作室中遇到这个问题。当我使用 g++ 或代码块编译时,它工作得非常好。
我调用模板的代码是:
MemDeSerialize(ListOfItems, SerializedData, size_t(Data[2]));
定义:
typedef struct
{
//......
} PanelItem;
std::vector<PanelItem> ListOfItems;
template<typename T>
void MemDeSerialize(T& Destination, unsigned char* &Source){...}
template<typename T>
void MemDeSerialize(T*& Destination, unsigned char* &Source, size_t Size){...}
template<typename T>
void MemDeSerialize(std::vector<T> &Destination, unsigned char* &Source, size_t Size)
{
Destination.resize(Size);
for (size_t I = 0; I < Size; ++I)
MemDeSerialize(&Destination[I], Source, Size);
}
/** FUNCTION OVERLOADS **/
void MemDeSerialize(Model* Destination, unsigned char* &Source);
void MemDeSerialize(PanelItem* Destination, unsigned char* &Source);
void MemDeSerialize(Compass* Destination, unsigned char* &Source);
void MemDeSerialize(FontChar* Destination, unsigned char* &Source);
我不断收到的错误是:
1>error C2665: 'MemDeSerialize' : none of the 6 overloads could convert all the argument types
1>could be 'void MemDeSerialize<PanelItem>(T *&,unsigned char *&,size_t)'
1> with
1> [
1> T=PanelItem
1> ]
1> while trying to match the argument list '(PanelItem *, unsigned char *, size_t)'
1> see reference to function template instantiation 'void MemDeSerialize<PanelItem>(std::vector<_Ty> &,unsigned char *&,size_t)' being compiled
1> with
1> [
1> _Ty=PanelItem
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
任何想法为什么?它在代码块中编译得很好;只是不是视觉工作室。
我一直这样称呼它:MemDeSerialize(ListOfItems, SerializedData, size_t(Data[2]));