typedef struct-c++重载运算符 +=报错

问题描述

c++重载运算符 +=报错

typedef struct UserInfo{
ULONGLONG m_ullReqNum;
ULONGLONG m_ullResNum;
ULONGLONG m_ullEmptyResNum;

}USERINFO_S;

typedef struct UserQueryReport{

std::map<std::string,USERINFO_S>m_strUserInfo;

void operator +=(const UserQueryReport& stReport) {
        std::map<std::string,USERINFO_S>::iterator itr;
        for( itr = stReport.m_strUserInfo.begin();itr!= stReport.m_strUserInfo.end();itr++)
        {
            m_strUserInfo[itr->first].m_ullReqNum+= stReport.m_strUserInfo[itr->first].m_ullReqNum ;
            m_strUserInfo[itr->first].m_ullResNum+= stReport.m_strUserInfo[itr->first].m_ullResNum ;
            m_strUserInfo[itr->first].m_ullEmptyResNum+= stReport.m_strUserInfo[itr->first].m_ullEmptyResNum ;

        }

 }

}UESRQUERYRPORT_S;

解决方案

error: no match for ‘operator=’
你看你哪里调用等号的。
贴出完整代码。main函数在哪

解决方案二:

顺便把错误代码发出来一下

解决方案三:

myoo.cpp: In member function ‘void UserQueryReport::operator+=(const UserQueryReport&)’:
myoo.cpp:21: error: no match for ‘operator=’ in ‘itr = stReport->UserQueryReport::m_strUserInfo.std::map<_Key, _Tp, _Compare, _Alloc>::begin with _Key = std::basic_string, std::allocator >, _Tp = UserInfo, _Compare = std::less, std::allocator > >, _Alloc = std::allocator, std::allocator >, UserInfo> >’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h:154: note: candidates are: std::_Rb_tree_iterator, std::allocator >, UserInfo> >& std::_Rb_tree_iterator, std::allocator >, UserInfo> >::operator=(const std::_Rb_tree_iterator, std::allocator >, UserInfo> >&)
myoo.cpp:23: error: passing ‘const std::map, std::allocator >, UserInfo, std::less, std::allocator > >, std::allocator, std::allocator >, UserInfo> > >’ as ‘this’ argument of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator [with _Key = std::basic_string, std::allocator >, _Tp = UserInfo, _Compare = std::less, std::allocator > >, _Alloc = std::allocator, std::allocator >, UserInfo> >]’ discards qualifiers
myoo.cpp:24: error: passing ‘const std::map, std::allocator >, UserInfo, std::less, std::allocator > >, std::allocator, std::allocator >, UserInfo> > >’ as ‘this’ argument of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator [with _Key = std::basic_string, std::allocator >, _Tp = UserInfo, _Compare = std::less, std::allocator > >, _Alloc = std::allocator, std::allocator >, UserInfo> >]’ discards qualifiers
myoo.cpp:25: error: passing ‘const std::map, std::allocator >, UserInfo, std::less, std::allocator > >, std::allocator, std::allocator >, UserInfo> > >’ as ‘this’ argument of ‘_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator [with _Key = std::basic_string, std::allocator >, _Tp = UserInfo, _Compare = std::less, std::allocator > >, _Alloc = std::allocator, std::allocator >, UserInfo> >]’ discards qualifiers
myoo.cpp: In function ‘int main()’:

解决方案四:

去掉const 问题解决,但不知道原因

时间: 2024-08-05 22:41:28

typedef struct-c++重载运算符 +=报错的相关文章

struct-为什么使用typedef修改数据类型名称的时候报错

问题描述 为什么使用typedef修改数据类型名称的时候报错 #define _CRT_SECURE_NO_DEPRECATE #include #include void main() { struct Member { char ID[7]; char name[10]; char sex; int age; int points; }; typedef Member ok; ok mem; printf("Input member ID:"); scanf("%s&qu

java用正则匹配运算符中的*号报错

问题描述 java用正则匹配运算符中的*号报错 这是用正则匹配一个四则运算算式中有几个数字的程序,将 * 号放在最后可以得出正确结果,但是将 * 号放中间的话就会报错,这是为什么?要怎么改? public class Blank { public static int f(String s) { return s.split("[+-\*/]").length; } public static void main(String[] args) { System.out.println(

报错:在经符号扩展的操作数上使用了按位“或”运算符;请考虑首先强制转换为较小的无符号类型

问题描述 在一个类中,有以下代码行,因为代码太长,省去其他部分.internalshortbi_buf;internalintbi_valid;internalvoidsend_bits(intvalue,intlength){intlen=length;unchecked{if(bi_valid>(int)Buf_size-len){//intval=value;//bi_buf|=(val<<bi_valid);bi_buf|=(short)((value<<bi_val

char[]-关于c++中char[ ] 的赋值报错问题

问题描述 关于c++中char[ ] 的赋值报错问题 iemi = pThis->imei; 第一个imei是typedef struct ServerInfoData { char iemi[128]; }ServerInfoData; 第二个imei是在头文件中被定义的private 中的char[128]; 但是在编译的时候就报错 ./Core/ServerManager.cpp:145:32: error: invalid array assignment 这是怎么回事啊 解决方案 楼主

求大神解答一下c++的题,重载运算符+,-,*,求矩阵的运算,做了好久没做出来

问题描述 求大神解答一下c++的题,重载运算符+,-,*,求矩阵的运算,做了好久没做出来 #include<iostream.h> #include<iomanip.h> class operation {public: static void rank(); //输入阶数 void array(); //输入矩阵 void display(); friend operation operator +(operation &,operation &); friend

c++-【下跪】PB调用C的DLL报错

问题描述 [下跪]PB调用C的DLL报错 一下是文档中的结构体: typedef struct{byte Track2[37]; /*二磁道信息 ,asc格式 最长37个字节 */byte Track3[104]; /*三磁道信息 asc 格式 最长 104个字节*/byte Pwd[8]; /*加密后的密码 8个字节 */byte Amount[12]; /* 金额, 分为单位000000000001 代表1分不允许0金额积分兑奖时为积分*/byte Trace[6]; /* 终端流水,不是动

数据结构、c语言-急!!!!为何以下程序执行第2功能离开车厂后在vc++6.0环境下程序会报错并终止运行,求解决方案

问题描述 急!!!!为何以下程序执行第2功能离开车厂后在vc++6.0环境下程序会报错并终止运行,求解决方案 #include "stdafx.h" #include #include #include #define max 5 #define pri 5 typedef struct time{ int year; int day; int month; int hour; int min; }Time; typedef struct node{ char num[10]; Tim

(C语言版)数据结构线性表从键盘输入元素实现相关功能,不报错,但执行意外终止

问题描述 (C语言版)数据结构线性表从键盘输入元素实现相关功能,不报错,但执行意外终止 #include #include #define MaxSize 50 typedef char ElemType; typedef struct{//struct结构体 ElemType data[MaxSize]; int length; }SqList; void InitList(SqList &L)//初始化线性表的方法,&是取地址符号,是定义指针符号,如int *b=&a:*a=4

编译器-C语言,编译和链接均未报错,运行时出现异常。

问题描述 C语言,编译和链接均未报错,运行时出现异常. 编译器报告异常信息(http://img.ask.csdn.net/upload/201508/30/1440920346_80190.png) 代码如下 #include #include #include #define TRUE 1 #define FASLE 0 #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef int Status; typedef struct el