整理: STL相关的编译错误

"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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值