Marco

Marco

  • NA
  • 59
  • 0

inerith-virtual - override

Sep 28 2007 10:09 AM
hi, I 've got a simple problem with subclass and method (I'll leave out some keywords to go direct to problem...). I hope you'll understand the problem....

abstract baseClass {
   List <baseClass> list = new List<BaseClass>();
   List<Two> list_two=new List<Two>();

   virtual add(BaseClass class) {
       list.Add(class);
       if (class.Type is "Two" also do.......)
             list_two.Add(class); //here error, because class hasn't same type of list_two...
  }
}


class One : baseClass {
    override void add(BaseClass class) {
              // do something
              base.add(class);
   }
}

class Two : baseClass{
         //constructor and the rest
}

main {
   Two two;
   One one;
   one.add(new two() );
}

Must I have refactor the classes or how can I do this things?
thanks...

Answers (7)