polymorphism

How to tell if MemberInfo represents an override

痞子三分冷 提交于 2019-12-11 12:00:00
问题 Given the following code: public class Base { public virtual void Method() { } } public class Derived : Base { public override void Method() { } } ... var baseMethodInfo = typeof(Base).GetMember("Method")[0]; var derivedMethodInfo = typeof(Derived).GetMember("Method")[0]; Is it possible to determine if the derivedMethodInfo represents a method declaration which overrides another in a base class? In another question it was observed that had Method been declared abstract (and not implemented)

Extending a base class to a derived class

大兔子大兔子 提交于 2019-12-11 11:39:36
问题 We have two classes BasicRace & AdvancedRace. AdvancedRace inherits from BasicRace I have a BasicRace but i want to 'convert' it to the advanced class. See code below as a example: Module Module1 Sub Main() Dim bRace As New BasicRace With {.CourseID = 1, .MeetingDate = "2013-05-01", .RaceNumber = 1} Dim aRace As New AdvancedRace ' Upgrade bRace to AdvancedRace??????? End Sub End Module Public Class BasicRace Public Property MeetingDate As Date Public Property CourseID As Integer Public

Create Polymorphic method on partial class to send generic type on c#

为君一笑 提交于 2019-12-11 10:57:41
问题 I want to implement a generic List procedure to various partial C# classes. I will use this generic method to fill comboboxes for filtering data. So far i have try this: Interface First I create a generic interface and a custom class public class Enumerador { public int ID{ get; set; } public string Description{ get; set; } } interface IEnumerador { IEnumerable<Enumerador> Enumerar(); } Then on every class i want this behavior I implement this interface like this: public IEnumerable

Creating an array of pointers of derivative class objects. C++. Abstract base class

给你一囗甜甜゛ 提交于 2019-12-11 10:50:03
问题 I need to make an array of 100 pointers to objects of two classes that are derived from an abstract class. First element of array is of class B , second is C , third is B etc. A is base and abstract class at the same time. For example: class A { public: A(); virtual double pureVirtualMethod() = 0; }; class B: public A { }; class C: public A { }; In main() I need to make an array of pointers that will point to any of the derived classes. I can't use Stl or Boost. 回答1: The comments are right.

Why is this an invalid use of Scala's abstract types?

若如初见. 提交于 2019-12-11 10:46:56
问题 I have this code: class A extends Testable { type Self <: A } class B extends A { type Self <: B } trait Testable { type Self def test[T <: Self] = {} } object Main { val h = new A // this throws an error h.test[B] } And my error is: error: type arguments [B] do not conform to method test's type parameter bounds [T <: Main.h.Self] h.test[B] On this question, it was said that this was due to path dependent types. Can anyone figure out how to have T <: Self, without having the path-dependent

“new” modifier causes base implementations to have NULL property values

久未见 提交于 2019-12-11 10:17:12
问题 I'm trying to use Polymorphism to have a derived class operate with a derived property instead of the base property. I'm not sure how to put it in clearer words, so here's an example with the output: // setup output to demonstrate the scenario static void Main(string[] args) { var foo = new Foo(); var foobase = foo as FooBase; Console.WriteLine("Foo is null? {0}", foo == null); Console.WriteLine("Foo.Bar is null? {0}", foo.Bar == null); Console.WriteLine("FooBase is null? {0}", foobase ==

Why are private methods not working with polymorphism?

一曲冷凌霜 提交于 2019-12-11 10:10:13
问题 Kind of got a problem using inheritance/polymorphism with private methods. Example: class cmsPage{ private function getBlock(){ $block = new cmsBlock(); return $block } function createBlock(){ $block = $this->getBlock(); $block->save(); } //... do various things } class specialCmsPage extends cmsPage{ private function getBlock(){ $block = new specialCmsBlock(); return $block } } Naturally I want specialCmsPage to inherit all the methods from cmsPage. The Function getBlock() should make sure

Accessing private members of a derived class C++ [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-11 10:08:09
问题 This question already has answers here : Can't access derived class method from pointer of type base class (3 answers) Closed 5 years ago . I am trying to access derived class' private members via an object of the base class. Here is what I'm trying to do : class A { private: int a, b; public: A(_a, _b) : a(_a), b(_b) {} int getA() { return a; } int getB() { return b; } }; class B : public A { private: int c; public: B(_a, _b, _c) : A(_a, _b), c(_c) {} int getC() { return c; } }; vector<A*>

Mapping over a list of existential types

旧巷老猫 提交于 2019-12-11 09:49:25
问题 I have a list of existientially-typed objects I want to map over. Something like this: sealed abstract class IntBox(val v: Int) case object IB1 extends IntBox(1) case object IB2 extends IntBox(2) case class Adder[A <: IntBox](ib: A, v: Int) { def add(i: A) = v + i.v } val adders: List[Adder[_ <: IntBox]] = List(Adder(IB1, 0), Adder(IB2, 0)) adders.map(adder => adder.add(adder.ib)) However, I'm getting an error like found: adder.ib.type required: _$1 I feel it's something like because the map

Problems with Laravel Many to Many Polymorphic Relationships

♀尐吖头ヾ 提交于 2019-12-11 09:38:15
问题 Really I need exactly what is in the Eloquent documentation. I need a tag system, with a polymorphic many to many relationship with users, posts, etc. The documentation doesn't seem to clearly state how to insert or update records with this relationship though... my attempts to do things like this: $user->tags()->save($tag); or $tag->users()->attach(Input::get('userID')); (which the above results in this error) {"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[23000]