整理: STL相关的编译错误

来源:互联网 发布:excel工作表数据保护 编辑:程序博客网 时间:2024/06/05 20:02

"error C2039: 'wstring' : is not a member of 'stlp_std'", 开发环境为: vs2005 + STLport-5.2.1 + unicode + winxpSp3

解决方法: #include <string>


<2011_1003>

STL使用结构时, 出现 error C2678 错误.

解决方法是重载操作符 ==, 而且要用在操作符定义后加 const 修饰

/*** @file testlist.cpp* stl's version is 5.2.1*/#include "stdafx.h"#include <windows.h>#include <list>#pragma pack(1)typedef struct _tag_UserInfo{    union    {        BYTE ucReserve[1024];        struct        {            INT iUserId;        };    };    /**    * error C2678:    * :\stlport-5.2.1\stlport\stl\_list.h(640) : error C2678: binary '==' :    * no operator found which takes a left-hand operand of type 'const _tag_UserInfo'    * (or there is no acceptable conversion)    */    //BOOL _tag_UserInfo::operator==(const _tag_UserInfo & param) /**< error */    BOOL _tag_UserInfo::operator==(const _tag_UserInfo & param) const /**< ok */    {        return (this->iUserId == param.iUserId) ? TRUE : FALSE;    }}TAG_USERINFO;#pragma pack()INT _tmain(INT argc, _TCHAR* argv[]){    TAG_USERINFO User;    std::list<TAG_USERINFO> myIntList;    ZeroMemory(&User, sizeof(TAG_USERINFO));    User.iUserId = 1;    myIntList.insert(myIntList.begin(), User);    myIntList.remove(User);/**< 需要重载 == 操作符, 否则出现 error C2678 错误 */    return 0;}