[Mono-list] cannot assign to <this> problem
Artur Karazniewicz
karaznie@acn.waw.pl
Sun, 29 Dec 2002 23:23:34 +0100
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.