[Mono-list] cannot assign to <this> problem

Arild Fines arild.fines@broadpark.no
Mon, 30 Dec 2002 02:15:15 +0100


Get rid of the 'ref' keyword in both places - it isn't needed(or allowed, as
you can see). You will get the semantics you want without it.

--
Arild Fines



> -----Original Message-----
> From: mono-list-admin@ximian.com [mailto:mono-list-admin@ximian.com]On
> Behalf Of Artur Karazniewicz
> Sent: 29. desember 2002 23:24
> To: mono-list@ximian.com
> Subject: [Mono-list] cannot assign to <this> problem
>
>
> Hello,
>
> I'm new to C# but I've coded a lot in C++ and
> I'm trying implement Visitor pattern
> in C# - and i'm not sure how to get double
> dispatch mechanism to work with C#.
>
> Example:
> I'm going to implement Visitor which changes
> some things in visited object. In C++ right
> way to do so is:
>
> // C++
> class Visitor {
>
> 	void Visit( Foo& aFoo ) {
> 		aFoo.SetSomething( "something" );
> 	}
>
> }
>
> class Foo {
>
> 	void Accept( Visitor& aVisitor ) {
> 		aVisitor.Accept( *this );
> 	}
>
> }
> //
>
> // it works fine but in C# code like this:
>
>
> // C#
> class Visitor {
>
> 	void Visit( ref Foo aFoo ) {
> 		aFoo.SetSomething( "something" );
> 	}
>
> }
>
> class Foo {
>
> 	void Accept( Visitor aVisitor ) {
> 		aVisitor.Accept( ref this );
> 	}
>
> }
>
> fails during compilation with message:
>
> error CS1604: Cannot assign to `this'.
>
> I dont know - how can I implement such kind
> of double dispatch in C#???
>
> regards
> Artur.
>
>
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list