Simple(?) Generics question [modified]
-
Any ideas what I'm really meant to be doing in the lines marked as "won't compile" below?
using System; namespace Test { public class MyClass : GenericsTest<> { public void DoSomething() { base.DoSomething(); } } public class GenericsTest<> where T : class { SomeHelperClass<> helper; public GenericsTest() { helper = new SomeHelperClass<>(); } public void DoSomething() { helper.DoSomething(T); // won't compile helper.DoSomething(this); // won't compile } } public class SomeHelperClass<> where T : class { public void DoSomething(T target) { } } }
TIA! -- modified at 21:11 Thursday 3rd August, 2006 Bah, the lt's and gt's get nuked when posting - just imagine the double lt's and gt's are actually single.. -- modified at 21:12 Thursday 3rd August, 2006 -
Any ideas what I'm really meant to be doing in the lines marked as "won't compile" below?
using System; namespace Test { public class MyClass : GenericsTest<> { public void DoSomething() { base.DoSomething(); } } public class GenericsTest<> where T : class { SomeHelperClass<> helper; public GenericsTest() { helper = new SomeHelperClass<>(); } public void DoSomething() { helper.DoSomething(T); // won't compile helper.DoSomething(this); // won't compile } } public class SomeHelperClass<> where T : class { public void DoSomething(T target) { } } }
TIA! -- modified at 21:11 Thursday 3rd August, 2006 Bah, the lt's and gt's get nuked when posting - just imagine the double lt's and gt's are actually single.. -- modified at 21:12 Thursday 3rd August, 2006Furty wrote:
just imagine the double lt's and gt's are actually single..
Or you could check the 'Ignore HTML tags in this message (good for code snippets)' box.
Furty wrote:
helper.DoSomething(T); // won't compile
T is a type. You want to pass in an instance of T. By the way, posting error messages is far more helpful that 'it won't compile'
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Any ideas what I'm really meant to be doing in the lines marked as "won't compile" below?
using System; namespace Test { public class MyClass : GenericsTest<> { public void DoSomething() { base.DoSomething(); } } public class GenericsTest<> where T : class { SomeHelperClass<> helper; public GenericsTest() { helper = new SomeHelperClass<>(); } public void DoSomething() { helper.DoSomething(T); // won't compile helper.DoSomething(this); // won't compile } } public class SomeHelperClass<> where T : class { public void DoSomething(T target) { } } }
TIA! -- modified at 21:11 Thursday 3rd August, 2006 Bah, the lt's and gt's get nuked when posting - just imagine the double lt's and gt's are actually single.. -- modified at 21:12 Thursday 3rd August, 2006Furty wrote:
helper.DoSomething(T); // won't compile
That should compile.
Furty wrote:
helper.DoSomething(this); // won't compile
That shouldn't compile. You are clearly passing the wrong type.
**
xacc.ide-0.2.0.50 - now with partial MSBuild support!
**