Sign in to follow this  

Pre/Post inc/dec-rement operator overloading support

This topic is 2655 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
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

This topic is 2655 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this