generaldusty
asked on
Overloading the ++ operator for a struct pointer
Hi,
I would like to overload the ++ operator for a pointer to a structure, so I can jump from one structure the the other.
Example code:
struct MyHeader
{
char length1;
char length2;
};
// &MyHeader + Length1 + Length2 + sizeof(MyHeader) = the memory adres where I can find the next header.
// example: 0x44444444 + 10 + 20 + 2 = 0x44444476
MyHeader *Header;
Header = (MyHeader)0x44444444; // some memory adres where there is a struct of the MyHeader kind.
// 0x44444444: 10
// 0x44444445: 20
// 0x44444476: 30
// 0x44444477: 40
Header->length1; // should be 10
Header++; // moving to the next header
Header->length1; // should be 30
So how can I overload the ++ operator for *MyHeader? Is this even possible?
sincerly,
Erik M.
I would like to overload the ++ operator for a pointer to a structure, so I can jump from one structure the the other.
Example code:
struct MyHeader
{
char length1;
char length2;
};
// &MyHeader + Length1 + Length2 + sizeof(MyHeader) = the memory adres where I can find the next header.
// example: 0x44444444 + 10 + 20 + 2 = 0x44444476
MyHeader *Header;
Header = (MyHeader)0x44444444; // some memory adres where there is a struct of the MyHeader kind.
// 0x44444444: 10
// 0x44444445: 20
// 0x44444476: 30
// 0x44444477: 40
Header->length1; // should be 10
Header++; // moving to the next header
Header->length1; // should be 30
So how can I overload the ++ operator for *MyHeader? Is this even possible?
sincerly,
Erik M.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
efn:
I was kinda hoping to avoid that solution, but if that's the only way so be it....
thnx for the quick reply, you get the point ;)
sincerly
Erik M.
I was kinda hoping to avoid that solution, but if that's the only way so be it....
thnx for the quick reply, you get the point ;)
sincerly
Erik M.
MyHeader *Header = ...;
Header++; // adds sizeof(MyHeader) to Header