[Mono-devel-list] Mono .net 2.0 preview and generics

Peter Wainwright prw at ceiriog1.demon.co.uk
Thu May 13 14:36:41 EDT 2004


On Thu, 2004-05-13 at 16:44, Gert Kello wrote:
> the method like
> public void Something(ref int Param)
> 
> must be called like
> 
> int aParam = 0;
> Something(ref aParam);

Yes, I understand this quite well. However, the problem is with the
generics, what in C++ we would call "automatic instantiation". The
relevant parts seem to be these:

public class Polysort {
  private static void swap<U>(ref U s, ref U t) {
    U tmp = s;  s = t;  t = tmp;    
  }
...
  private static void qsort<T>(T[] arr,
                               IGComparer<T> cmp,
                               int a, int b) {
...
          swap<T>(ref arr[i], ref arr[j]);           
  }
...
}

This seems perfectly OK to me: ref arr[i] is a ref T, not so? And
therefore should be a valid argument to swap<T>?

BTW the example is not mine - it is from 
http://www.dina.dk/~sestoft/gcsharp/#quicksort
but it exemplifies the complex generic container class stuff I need
to get working.
Can you tell me whether the code is meant to compile under the .NET
2.0 standard or whether the failure is a bug in Mono?

Peter Wainwright

> 
> > [prw at desdemona generics]$ gmcs Gsort.cs
> > Mono C# Compiler 0.91.0.0 for Generics
> > Gsort.cs(70) error CS1502: The best overloaded match for method 'void Polysort.swap (T, T)' has some invalid arguments
> > Gsort.cs(70) error CS1503: Argument 0: Cannot convert from 'ref T' to 'T'
> > Gsort.cs(103) error CS1502: The best overloaded match for method 'void Polysort.swap (T, T)' has some invalid arguments
> > Gsort.cs(103) error CS1503: Argument 0: Cannot convert from 'ref T' to 'T'
> > Compilation failed: 4 error(s), 0 warnings
> > 
-- 
Peter Wainwright <prw at ceiriog1.demon.co.uk>



More information about the Mono-devel-list mailing list