polymorphism

How can I create a type with multiple parameters in OCaml?

I'm trying to create a type that has multiple type parameters. I know how to make a type with one parameter: type 'a foo = 'a * int But I need to have two parameters, so that I can parameterize the 'int' part. How can I do this? ...

Polymorphism and array of pointers problem in C++

Hi, I'm working on a project and it's in a stage that I don't know what's wrong. Here's the simplified version: The code: class Base { // This base class is pure abstract public: virtual ~Base(); // Necessary to trigger destructors in inherited classes virtual baseFunc() = 0; }; ...

How to make Haskell compute the correct polymorphic type?

I just realized how useful the little on-function can be. Ex: orderByLength = sortBy (compare `on` length) But unfortunately, the inferred types can be somewhat counter-intuitive. According to the very definition f `on` g = \x y -> f (g x) (g y) one could e.g. replace (==) `on` length with \x y -> (length x) == (length y) B...

vptr - virtual tables

hey, there is something i still don't get. for every class i declare there is a hidden vptr member pointing to the class virtual table. let's say i have this declaration : class BASE { virtual_table* vptr; //that's hidden of course , just stating the obvious virtual void foo(); } class DERIVED : public BASE { virtual_tabl...

Why does this work? Method overloading + method overriding + polymorphism

In the following code: public abstract class MyClass { public abstract bool MyMethod( Database database, AssetDetails asset, ref string errorMessage); } public sealed class MySubClass : MyClass { public override bool MyMethod( Database database, AssetDetails asset, ref string errorMe...

Help creating a functional hierarchy

I'm trying to create my first hierarchy with the following classes (Account, CheckingAccount, and SavingsAccount) and can't figure out how to link the classes together. Also, should the balance value be public in the header? Currently it is not, and it shows "error in this context" every time it's mentioned in this main code. [stackover...

Rails Changing Polymorphic Type Of An Object

We have a parent model Vehicle that is inherited to make classes Car, Truck, SUV. In our form, we allow the user to edit the data for a bunch of Vehicles, and one of the attributes for each vehicle is a select menu for "type". The HTML attribute is named vehicle_type and updates the actual Polymorphic type attribute in the Vehicle Model:...

Need sample problems for hands-on

I have been working with C++ for a few years now and have got good theoretical knowledge on the matter (I think). However I've been missing involvement in good projects, sort of projects that really gets one going on the technologies. So I intend to work on my own to get some good grip on C++ and related technologies. 'Have started with ...

C++ What is compile-time polymorphism and why does it only apply to functions?

The question is pretty much fully embedded in the title. ...

Inherit from a template parameter and upcasting back in c++

Hello, I have tried to use this code in VS2008 (and may have included too much context in the sample...): class Base { public: void Prepare() { Init(); CreateSelectStatement(); // then open a recordset } void GetNext() { /* retrieve next record */ } private: virtual void Init() = 0; virtu...

Inheritance mucking up polymorphism in C++?

Perhaps my knowledge of inheritance and polymorphism isn't what I thought it was. Can anyone shed some light? Setup (trivialization of problem): class X { }; class Y { }; class Base { public: void f( X* ) {} }; class Child: public Base { public: void f( Y* ) {} }; Question: This should work, right? int main( void ) {...

Rails User model has_many activities (observer) but should also be observed

I'm running into an issue with an existing ActiveRecord::Observer model that records various Activities of a User the site. Everything was working really well, until I tried to observe the User class with the same Activity model that it uses to observe other models. Consider that: class Activity < ActiveRecord::Base belongs_to :user b...

abstract class and using array polymorphically

i'm just reading meyers "More Effective C++ 35 New Ways" - item 33, and he suggest there always to inherit from an abstract base class, and not a concrete. one of the reason he claims, which i can't quite get , is that with inheriting from an abstract class, treating array polymorphically (item 3 in the book) is not a problem. can some...

Polymorphism Trouble C Sharp

Im trying to make something like an Rpg game atm but im really stuck on something i really dont know what to do anymore i really need help it might look like a noob question but please try to answer me >.< this is the parent class namespace ConsoleApplication1 { class Personaje { public Rango Damage; public int D...

Polymorphism Trouble C Sharp Part 2 >.<

im trying to use this method to make my characters but i get the error: inconsistent accessibility:return type'consoleapplication1.Enemigo' is less accesible than method 'consoleapplication1.poringbuilder.makeporing()' its the first time i get this error and i really dont know what to do,i have tried alot of different ways but i get the ...

Service - client interface, architecture advice

Hi, I have a Windows WCF serivce and Web client. My service has one method [OperationContract] SubmitOrder(OrderInfo info).... // class used to pass all relevant data [DataContract] class OrderInfo { [DataMember] OrderType Type; // general order data } It was great until I have introduced new order types (controlled by OrderInfo....

Is there a way to automaticly call all versions of an inherited method?

I'm writing a plug-in for a 3D modeling program. I have a custom class that wraps instances of elements in the 3D model, and in turn derives it's properties from the element it wraps. When the element in the model changes I want my class(es) to update their properties based on the new geometry. In the simplified example below. I have c...

methods overriding and overloading

can i overload or override methods just by using different return value ? is virtual matter in thie case ? for example : class A{ virtual int Foo(); // is this scenario possible with/without the keyword virtual } class B : public A { virtual double Foo(); } A* Base = new B(); int i = Base->Foo(); // will this just convert doubl...

What does the ocaml type 'a. 'a -> 'a mean?

In the ocaml language specification, there's a short section: poly-typexpr ::= typexpr | { ' ident }+ . typexpr There's no explanation in the text, and the only instance of poly-typexpr is in defining a method type: method-type ::= method-name : poly-typexpr What does this allow me to do? ...

Doubt on using polymorphism in coding an expression parse tree/evaluator

I am working on an interpreter for a toy language, just to learn about building an interpreter. I have already implemented a simple parser for the grammar that generates a parse tree. Now, the usual way of evaluating the parse tree would be to use polymorphism on the nodes of the parse tree, with code that looks something like below (in ...