inheritance

How to use an overridden constant in an inheritanced class

Hey, given this code: class A CONST = 'A' def initialize puts CONST end end class B < A CONST = 'B' end A.new # => 'A' B.new # => 'A' I'd like B to use the CONST = 'B' definition, but I don't know how. Any ideas? Greetings Tom ...

Memory implementation of member functions in C++

I read an article on virtual table in Wikipedia. class B1 { public: void f0() {} virtual void f1() {} int int_in_b1; }; class B2 { public: virtual void f2() {} int int_in_b2; }; used to derive the following class: class D : public B1, public B2 { public: void d() {} void f2() {} // override B2::f2() int int_in_d; };...

Virtual inheritance in C++

I was reading the Wikipedia article on virtual inheritance. I followed the whole article but I could not really follow the last paragraph This is implemented by providing Mammal and WingedAnimal with a vtable pointer (or "vpointer") since, e.g., the memory offset between the beginning of a Mammal and of its Animal part is...

Rails3: warning: toplevel constant ApplicationController referenced by ...

Everytime i get a warning: app/controllers/agency/agencies_controller.rb:1: warning: toplevel constant ApplicationController referenced by Agency::ApplicationController My agencies_controller.rb: class Agency::AgenciesController < Agency::ApplicationController def index ... end ... end And Agency::ApplicationController...

Django Inheritance and Permalinks

Hi, I'm creating a simple CMS in django, with multiple "modules" (each as a django app). I've set up the following models: class FooObject(models.Model): id = models.SlugField(primary_key=True) name = models.CharField(max_length=255) creator = models.ForeignKey(auth.models.User, editable=False, related_name="createdby") cl...

mxml inheritance in Flex. how works "instanceof" and "is"?

Hi2all! Earlier i used following structure: Canvas -> Screen1 Canvas -> Screen2 When I feel need in common logic in my application I do next: Canvas -> Screen Screen -> Screen1 Screen -> Screen2 So when I try to apply it in my code if(child is Screen){ return child.localToGlobal(new Point()).x; } It is not works! When I see ...

How to convert class to inherited class while using ActiveRecord

I've got a class Project and a class Case, which inherits from Project. When having a list of Projects we might decide later on to make a Case of the selected Project. How can I achieve this? Project: [ActiveRecord (Table = "projects", Lazy = true), JoinedBase] public class Project : ActiveRecordValidationBase<Project> { priva...

Peculiar Behaviour with PHP (5.3), static inheritance and references.

I'm writing a library in PHP 5.3, the bulk of which is a class with several static properties that is extended from by subclasses to allow zero-conf for child classes. Anyway, here's a sample to illustrate the peculiarity I have found: <?php class A { protected static $a; public static function out() { var_dump(static::$a); } ...

Getting child class type from parent class parameter in C#

I am going to have multiple "types" of an object and I am really not sure how best to retrieve/save those multiple types without having a separate save/retrieve for each type. My classes: public class Evaluation { public int Id public string Comment } public class EvaluationType_1 : Evaluation { public string field } public cla...

Inheritance Costs in C++

Taking the following snippet as an example: struct Foo { typedef int type; }; class Bar : private Foo { }; class Baz { }; As you can see, no virtual functions exist in this relationship. Since this is the case, are the the following assumptions accurate as far as the language is concerned? No virtual function table will be creat...

JavaScript Object.create -- inheriting nested properties

Hi There, I've come across a peculiarity with Douglas Crockfords Object.create method which I'm hoping someone might be able to explain: If I create an object - say 'person' - using object literal notation then use Object.create to create a new object - say 'anotherPerson' - which inherits the methods and properties from the initial 'p...

An inheritance example in python

I'm not clear how to pose this question. If I did, I'd probably be a lot closer to a solution.. I need some insight into inheritance. I want to make a custom subtype of float. But I want the instance of this subtype to re-evaluate it's value before performing any of the normal float methods (__add__,__mul__, etc..). In this example ...

Simple class abstraction in php does not work (conflicting names?)

Here is the simple php code <? abstract class A{ abstract public function a($x); } class B extends A{ public function a($x) { echo $x; } } $q = new B; $q->a(10); ?> which gives: PHP Fatal error: Cannot call abstract method A::a() but changing the name of the function to something else than "a" works. So what is really happening ...

Refactoring inheritance to composition using Vbex2005

I have a class that I wrote fairly early on in my vb.net programming experience which inherited from another class it really should have composed. The base class is a relatively generic nested dictionary-based collection; let's call the descendant class a "Car". Right now there's a lot of code that does things like 'MyCar!Color.st = "R...

How do I register types with boost serialization in a template class?

I am having a problem where I am trying to serialize a message of a template class. The template's class message is of type BaseClass, but I want it to serialize the derived versions of the class. As of right now, it is only serializing the BaseClass. How am I supposed to register with boost::serialization the types of the derived classe...

Controller inheritance in Ruby on Rails -- model and controller access in parent class

I am using single table inheritance in StudentHours and TeacherHours, which have a parent Hours. The model code is mostly in hour.rb, and very little in student_hour.rb and teacher_hour.rb Now I have realized that most of the controller code is duplicate as well, so I've created a hours_controller to be the parent of students_controlle...

Strange Inheritance Issue with C# classes

public class DTOa { public int Id { get; set;} public string FirstName { get; set;} } public class DTOb: DTOa { public string Email { get; set;} public string Password { get; set; } } public class a { protected DTOa _DTO = new DTOa(); public int Id { get { return _DTO.Id; ...

How to simulate multiple inheritance in C#

How can I do this: Class A : DependencyObject {} Class B : DependencyObject {} Class C : A , B {} ...

Rails DB Seeding

For some reason, the food_id field in 'ratings' isn't populating when I run the seed.rb file below. Can somebody help me figure out why? Seed file contains the following lines: Food.create(:id => 1, :description => 'Stonyfield Farm Yomommy 4oz. Strawberry') OverallRating.create(:score => 0, :count => 1, :food_id => 1) Code for Food ...

Avoiding dynamic_cast in implementation of virtual functions in derived class

Here is some sample code explaining what I am trying to achieve. Basically, I have an algorithm that depends on some basic operations available in a class. I have defined those operations in a pure abstract base class. I want to apply that algorithm to a variety of objects that provide those operations by deriving classes for the specif...