🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tangent: this-properties part 2.

Published July 06, 2009
Advertisement
I'm not sure what the deal is with my new car. It must look fast or something. I've gotten pulled over for speeding more times in the past week with the new car than I did in 9 years with the old. Warnings only thankfully. It's not as though I'm driving any differently. Seriously troopers, it's probably not the best use of your time to profile against station wagons; even sporty ones.

Anyways, the last example I posted on this-properties was not quite complete. If you tried to assign one to another, you'd get an ambiguity error since the compiler couldn't figure out if you wanted to assign the property or the contents. So I quickly implemented an Unassignable type, that essentially prevents a reference from being modified after it's been allocated. Useful for this exercise, and for a few others I'd imagine. It'll cause some weirdness once template methods are implemented, but I'll deal with that bridge when it comes along.

The test code for this change (pardon the poor naming):

public class   field: Unassignable{	private int x;	public int this{		get{			return(x);		}		set{			x = value;		}	}}public static main()=>void{	local field n;	local field p;	p=5;	n=p;	print n;}


Before, the 2nd to last line would cause error. Technically the declaration/initialization itself would produce error since it goes through and does proper assignment as well.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement