Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7439309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:41:16+00:00 2026-05-29T10:41:16+00:00

base class class Drawer { public abstract void Draw<T>(T type); } derived class #1

  • 0

base class

class Drawer
{
    public abstract void Draw<T>(T type);    
}

derived class #1

class ADrawer : Drawer
{
    public override void Draw<T>(List<T> list)
    {
        foreach (var a in list)
        {
            DrawA(a);
        }
    }

    public void DrawA(Agent a)
    {
        //draw code here
    }
}

derived class #2

class AnotherDrawer : Drawer
{
    public override void Draw<T>(T number)
    {
        if (number == 1)
        {
            //draw code
        }
    }
}

The error is in the #1 derived class : “no suitable method found to override”

Should I be using ‘virtual’ in the base class as well as ‘abstract’ ?

How should I set the base parameter type to allow a variety of parameters in derived classes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:41:17+00:00Added an answer on May 29, 2026 at 10:41 am

    Your code has more problems than just the one you ask about. Setting aside the override question for the moment, class ADrawer needs a type constraint (where T : Agent):

    class ADrawer : Drawer 
    { 
        public void Draw<T>(List<T> list) where T : Agent
        { 
            foreach (var a in list) 
            { 
                DrawA(a); 
            } 
        }
        public void DrawA(Agent a) 
        { 
            //draw code here 
        } 
    } 
    

    Without that constraint, it’s not legal to pass a to DrawA, because a is a reference of type T, and without the constraint there is no implicit conversion from type T to type Agent.

    The AnotherDrawer class has an illegal use of the == operator. It’s not possible to apply the == operator to operands of type T and int. You could get around that by using the object.Equals override.

    Finally, the base class has an error because it is a non-abstract class containing an abstract member.

    In general, however, this code indicates that the class should be generic, rather than the method:

    abstract class Drawer<T>
    {
        public abstract void Draw(T type);
    }
    

    derived class #1

    class ADrawer : Drawer<List<Agent>>
    {
        public override void Draw(List<Agent> list)
        {
            foreach (var a in list)
            {
                DrawA(a);
            }
        }       
    
        public void DrawA(Agent a)
        {
            //draw code here
        }
    }
    

    derived class #2

    class AnotherDrawer : Drawer<int>
    {
        public override void Draw(int number)
        {
            if (number == 1)
            {
                //draw code
            }
        }
    }
    

    To follow up on Eric Lippert’s comment, which was also my first reaction to your question, you might consider this design instead:

    abstract class Drawer<T>
    {
        public abstract void Draw(T type);
        public void DrawMany(IEnumerable<T> types)
        {
            foreach (var t in types)
                Draw(t);
        }
    }
    

    derived class #1

    class ADrawer : Drawer<Agent>
    {
        public override void DrawA(Agent a)
        {
            //draw code here
        }
    }
    

    Derived class #2 is unchanged.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Base { public: Base() {} void Foo(int x) {...} }; class Derived :
class Base { public: virtual void foo() {} }; class Derived: public Base {
A base class have readonly field of type List<SomeEnum> which the derived classes will
I've got a base class: public abstract class StuffBase { public abstract void DoSomething();
I have a base class ReportElement which has type property: public abstract class ReportElement
In base class constructors I always see a parameterless constructor, like so: public abstract
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
Given the base class A and the derived class B: class A { public:
I have an abstract base class and two derived classes. The base class contains
class Base { public void add() { System.out.println(Base ADD); } void subtract() { throw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.