Still Struggling with map::insert and operator overload
-
Hi I am still having problems with map::insert Here is my data
struct usingx
{
unsigned char rectype;
#define using 0
#define pop 0x20
#define push 0x40
#define drop 0x80
unsigned char usingflag
#define oridinaryusing 0
#define labeledusing 0x10
#define depedentusing 0x20
#define labeldependentusing 0x30
; ESDID locesdid;
BYTE statement[4];
BYTE location[4];
BYTE usingvalue[4];
BYTE laststatement[4];
ESDID usingesdid;
unsigned char registerx;
BYTE displacement[2];
BYTE reservedz;
BYTE usingrange[4];
BYTE reservedu[2];
BYTE labeloffset[4];
BYTE labelength[4];
char* labelx;};
Here is the key that I am using the start and end variable are big endian so I have to convert it and overloaded the = operator;
struct usingrange
{
ESDID esdid;
int start;
int end;
int operator=(BYTE z[4]) { return _byteswap_ulong((int)z[4]); };bool operator<(const usingrange x) const {
if (esdid < x.esdid) return esdid < x.esdid;
if (start < x.start) return start < x.start; if (end < x.end) return end < x.end;
};here is the code using the map::insert
usingrange using\_range{ usingpoint->usingesdid }; using\_range.start = \*usingpoint->statement; using\_range.end = \*usingpoint->laststatement; procpointer->usingptr->insert({ using\_range,\*usingpoint }); break;
I made breakpoints on the operator= code and thought when I stepped into it with the vs debugger it would trace it but it didnt both start and end ended up zeros dont know why ?
-
Hi I am still having problems with map::insert Here is my data
struct usingx
{
unsigned char rectype;
#define using 0
#define pop 0x20
#define push 0x40
#define drop 0x80
unsigned char usingflag
#define oridinaryusing 0
#define labeledusing 0x10
#define depedentusing 0x20
#define labeldependentusing 0x30
; ESDID locesdid;
BYTE statement[4];
BYTE location[4];
BYTE usingvalue[4];
BYTE laststatement[4];
ESDID usingesdid;
unsigned char registerx;
BYTE displacement[2];
BYTE reservedz;
BYTE usingrange[4];
BYTE reservedu[2];
BYTE labeloffset[4];
BYTE labelength[4];
char* labelx;};
Here is the key that I am using the start and end variable are big endian so I have to convert it and overloaded the = operator;
struct usingrange
{
ESDID esdid;
int start;
int end;
int operator=(BYTE z[4]) { return _byteswap_ulong((int)z[4]); };bool operator<(const usingrange x) const {
if (esdid < x.esdid) return esdid < x.esdid;
if (start < x.start) return start < x.start; if (end < x.end) return end < x.end;
};here is the code using the map::insert
usingrange using\_range{ usingpoint->usingesdid }; using\_range.start = \*usingpoint->statement; using\_range.end = \*usingpoint->laststatement; procpointer->usingptr->insert({ using\_range,\*usingpoint }); break;
I made breakpoints on the operator= code and thought when I stepped into it with the vs debugger it would trace it but it didnt both start and end ended up zeros dont know why ?
The line
usingrange using_range{ usingpoint->usingesdid };
does not invoke your assignment operator. This is a constructor and it will just copy the argument. Not sure where you expected the assignment to be invoked. I would replace the assignments with a constructor similar to this:
struct usingrange
{
usingrange(usingx& x) {
esdid = byte_swap(x.usingesdid;
start = x.statement;
end = x.laststatement;
//…
}
ESDID esdid;
int start;
int end;As a comment, your comparison operator is suboptimal and incomplete. I’m surprised you didn’t get a warning that not all control paths return a value.
Mircea
-
The line
usingrange using_range{ usingpoint->usingesdid };
does not invoke your assignment operator. This is a constructor and it will just copy the argument. Not sure where you expected the assignment to be invoked. I would replace the assignments with a constructor similar to this:
struct usingrange
{
usingrange(usingx& x) {
esdid = byte_swap(x.usingesdid;
start = x.statement;
end = x.laststatement;
//…
}
ESDID esdid;
int start;
int end;As a comment, your comparison operator is suboptimal and incomplete. I’m surprised you didn’t get a warning that not all control paths return a value.
Mircea