derived-types

What is this C++ technique for adding types to a class called?

I've just found some C++ code (at http://msdn.microsoft.com/en-us/library/k8336763%28VS.71%29.aspx), which uses a technique I've never seen before to add types to an existing class: class Testpm { public: void m_func1() { cout << "m_func1\n"; } int m_num; }; // Define derived types pmfn and pmd. // These types are pointers to mem...

Deriving a type and its dependencies

Hi, I've been playing with newtype wrappers for my indexes to avoid bugs, and I have some code like this: {-# LANGUAGE GeneralizedNewtypeDeriving #-} newtype PersonIdx = PersonIdx Int deriving (Enum, Eq, Integral, Num, Ord, Real, Show) To derive Integral, one must derive all its dependencies as well (hence the above list of type-cl...

How do you make a Factory that can return derived types?

I have created a factory class called AlarmFactory as such... 1 class AlarmFactory 2 { 3 public static Alarm GetAlarm(AlarmTypes alarmType) //factory ensures that correct alarm is returned and right func pointer for trigger creator. 4 { 5 switch (alarmType) 6 { 7 case AlarmTypes....

Pass a list of types, limiting the types to classes derived from a particular parent, in c#

I have a method on an object oriented database that creates tables based on their type. I want to be able to send a list of types to get created, but i'm hoping to limit them to only classes derived from a specific base class (MyBase). Is there a way i can require this in the method signature? Instead of CreateTables(IList<Type> tabl...

How does deriving work in Haskell?

ADTs in Haskell can automatically become instance of some typeclasses (like Show, Eq) by deriving from them. data Maybe a = Nothing | Just a deriving (Eq, Ord) My question is, how does this deriving work, i.e. how does Haskell know how to implement the functions of the derived typeclass for the deriving ADT? Also, why is derivi...