inheritance

Multiple Constructors in Scala should call different super methods

Possible Duplicate: In Scala, how can I subclass a Java class with multiple constructors? Hello all clever people I'm currently having a little problem where I need to invoke different super methods based on which constructor I invoke. In short it is something like this: class HelpfulJList(model: ListModel) extends JList(mo...

C++: Why does my DerivedClass's constructor not have access to the BaseClass's protected field?

I have a constructor attempting to initialize a field in a base class. The compiler complains. The field is protected, so derived classes should have access. //The base class: class BaseClass { public: BaseClass(std::string); BaseClass(const BaseClass& orig); virtual ~BaseClass(); const std::string GetData() const; ...

C++ template duck-typing vs pure virtual base class inheritance

Which are the guidelines for choosing between template duck-typing and pure virtual base class inheritance? Examples: // templates class duck { void sing() { std::cout << "quack\n"; } }; template<typename bird> void somefunc(const bird& b) { b.sing(); } // pure virtual base class class bird { virtual void sing() = 0; }; c...

How to implement or use inheritance in JavaScript?

Possible Duplicate: Performing Inheritance in Javascript What are the ways to implement inheritance in JavaScript Which one is the best and why? ...

Semi-inheritance in C: How does this snippet work?

Hi everyone, One way to hack limited form of polymorphism in C is to do something like this: typedef struct { int x; } base; typedef struct { base super; int y; } derived; Now you can refer to a derived instance as a base instance, depending on how the variable is cast, ie: derived my_derived; my_derived.y = 10; my_der...

BaseClass method which returns an arbitrary subclass of BaseClass

In my game I have a base class of Loot which has methods universal to anything which can be picked up by the player and stored in his inventory. This would include potions, equipment, ammo, etc. I can equip arrows, but not potions. So Arrow would be a subclass of Ammo, which would ultimately derive from Loot. I can drink a potion but not...

Confused with C++ Inheritance

I'm so confused with the output of the following code: #include <iostream> using namespace std; class Parent { public: Parent() : x(2) { } virtual ~Parent() { } void NonVirtual() { cout << "Parent::NonVirtual() x = " << x << endl; } private: int x; }; class Child : public Parent { public: Child() : x(1) { } ...

Scala class cant override compare method from Java Interface which extends java.util.comparator

Hello All I'm currently working on a port of a jEdit plugin to write all code in Scala. However Im forced at a certain point to implement my own Comparator. My simplified code is as follows: class compare extends MiscUtilities.Compare { def compare(obj1: AnyRef, obj2: AnyRef): Int = 1 } The MiscUtilities.Compare has the following ...

Is there a way to inherit properties from multiple classes in C#?

Possible Duplicate: Multiple Inheritance in C# In the following example, I want the Shirt to automatically inherit the properties of both the Material and Pigment classes. Is this even possible in C#? public class Material { public enum FabricTypes { Cotton, Wool, Polyester, Nylon } public FabricTypes Fabric { get; se...

How can I know whether a class is inherited from another one? Some methods like is_a?

Simple example: class A end class B < A end Then, how can I judge whether class B is inherited from class A? Is there a method somehow like is_a? or maybe called is_child_of?? I can't find one. ...

State of Derived class object when Base class constructor calls overridden method in Java

Please refer to the Java code below: class Base{ Base(){ System.out.println("Base Constructor"); method(); } void method(){} } class Derived extends Base{ int var = 2; Derived(){ System.out.println("Derived Constructor"); } @Override void method(){ System.ou...

How can you retrieve all records of certain subtype dynamically with Linq to Entities?

I am trying to get a list of all objects in the database of a specified type. I have done this before when the type was known at compile time, but now I am trying to pass a type into the method and have the method return all the records of that specified type, and I can't get it working. I have tried the following: public IList<W...

PHP Object Extension $this->some_object->method

I am trying to make a script in which different classes (e.g. Database, Utilities, Config) are all used to form one central Main class. I have tried extending a chain of them: Main -> Utilities -> Database -> Configuration But how can I set the different parts so that they can be called like this: <?php $this->db->select("WAFFLE...

usage of class inheritance in django for polymorphism?

Dear friends, I need your help in the following matter : in my django models, the following classes exist : class QItem(models.Model) class Question(QItem) class QuestionSet(QItem): items = models.ManyToManyField(QItem, blank=True, null=True, through='Ordering', related_name="contents") class Ordering(models.Model): item ...

Scala inheritance from Java class: select which super constructor to call

I have multiple constructor in a Java class. public class A{ public A(){...} public A(String param){...} public A(String param, Object value} } Now I want to create a Scala class that inherit from that class class B extends A{ super("abc") } But this syntax is invalid. Scala is complaining that '.' expected but '(' found. ...

How to implement an interface explicitly with a virtual method?

I can't do this interface InterfaceA { void MethodA(); } class ClassA : InterfaceA { virtual void InterfaceA.MethodA() // Error: The modifier 'virtual' is not valid for this item { } } Where the following works class ClassA : InterfaceA { public virtual void MethodA() { } } Why? How to circumvent th...

Codeigniter and multiple inheritance

I've been using Codeigniter to construct the front end of a moderately sized application, and have run into an issue with--what I think may be--inheritance in PHP. Here is what I am trying to do: In following the MVC architecture, I found that I was duplicating a lot of code across models, and decided to create a common Model from which...

Can an Android View's id be safely shared across multiple Activities?

Say I have two Activities in an Android application, EditPerson and EditEmployee. It would seem natural to have the EditPerson Activity be a base class for the EditEmployee Activity and define methods that marshal data to and from the Views defined in the layout. The EditPerson Activity's implementation would push (for example) the "Na...

Why do IsAssignableFrom and GetInterface give different results.

I have created a type like this: TypeBuilder tb = moduleBuilder.DefineType(myname, TypeAttributes.Class | TypeAttributes.Public, typeof(BaseClass), new Type[] { typeof(ImyInterface) }); Then lots of ilgenerating code follows for constructors, methods etc. When I start using the class I noticed something strange. I want to check...

Inheritance and pointers to pointers: why doesn't it work and how do I get around it?

Why do I get a compilation error when I call a base-class function with a pointer to a pointer to an inherited class? Example: class cFoo {}; class cBar : public cFoo {}; void func1(cFoo *) {} // base class void func2(cFoo **) {} // base class void main(void) { cBar bar, *pbar; // inherited class func1(&bar); // compiles ...