Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Simple(?) Generics question [modified]

Simple(?) Generics question [modified]

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Furty
    wrote on last edited by
    #1

    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

    C L 2 Replies Last reply
    0
    • F Furty

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Furty 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

      1 Reply Last reply
      0
      • F Furty

        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

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        Furty 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!

        **

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups