Properties

Michel Fortin michel.fortin at michelf.com
Fri Jan 9 03:56:03 PST 2009


On 2009-01-09 05:47:26 -0500, Yigal Chripun <yigal100 at gmail.com> said:

> that's solvable. as I noted in a previous post, a property seems to me 
> to be mainly syntax sugar for a struct like in the following snippet:
> 
> class A {
> 	struct Prop {
> 		int internal;
> 		int opCall() { return internal; }
> 		void opAssign(int value) { internal = value; }
> 	}
> 	public Prop prop;
> 	...
> }

Hum, that doesn't really work. Getter and setters of the property have 
access to the whole class scope, and can call functions of that class. 
If you wanted to extract a property from a class, you'd have to do it 
by keeping a pointer to the class, not the property's value:

	class A {
		private int internal;
		struct Prop {
			A outerClass;
			int opCall() { return outerClass.internal; }
			void opAssign(int value) { outerClass.internal = value; }
		}
		public Prop prop;
	}


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list