Jump to content
  • Advertisement
Sign in to follow this  
droz

Pre/Post inc/dec-rement operator overloading support

This topic is 2961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I needed to be able to register increment operators for some of my classes, so I added support for this to angelscript. I named the operator functions opPreInc, opPreDec, opPostDec & opPostInc. It works for both script and application classes.

If I recall you prefer the full file so you can run a diff on it, you can get it at http://home.comcast.net/~jeremyh/as_compiler.cpp. The file is from the latest revision (676).

Thanks,
Jeremy

Share this post


Link to post
Share on other sites
Advertisement
Forgot to mention that I think it should throw a error if you try to use this on a const object or handle, for example this will work:


class Test {
int num;
Test() {
num = 0;
}
void opPreInc() {
print(++num);
}

void opPostInc() {
print(num++);
}
}


void main() {
const Test t;
const Test @h = t;
h++;
}



So this needs to be fixed, if I get some time when I get home from work I will try to fix it.

This will not work:

class Test {
int num;
Test() {
num = 0;
}
void opPreInc() {
print(++num);
}

void opPostInc() {
print(num++);
}
}

void main() {
const Test t;
t++;
}



You will just get " Reference is read-only" which is correct.

Share this post


Link to post
Share on other sites
I've added this to the library in revision 687. My implementation is different though, as I reused the code I already had for the unary operators opNeg (-) and opCom (~). Let me know if you find any problems with it.

Thanks for the contribution.

Share this post


Link to post
Share on other sites
Thanks for adding this. Your implementation is much better, as mine needlessly duplicated a lot of code.

Thanks,
Jeremy

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!