Arrays of many different (sub)classes

2010-04-24 Thread Joseph Wakeling
Hello all, Occasionally in C++ I find it useful to build an array which contains classes of multiple different types all using the same interface -- by constructing an array of pointers to some common base class, e.g. class BaseClass { // blah, blah ... }; class A : BaseClass { // ... bl

Re: Arrays of many different (sub)classes

2010-04-24 Thread Robert Clipsham
On 24/04/10 20:06, Joseph Wakeling wrote: Hello all, Occasionally in C++ I find it useful to build an array which contains classes of multiple different types all using the same interface -- by constructing an array of pointers to some common base class, e.g. class BaseClass { // blah, bla

Re: Arrays of many different (sub)classes

2010-04-25 Thread Joseph Wakeling
Robert Clipsham wrote: > This should do what you want: Thanks! :-) Is it possible to do this with an interface instead of a base class? I'm not familiar with how the former work ... Best wishes, -- Joe

Re: Arrays of many different (sub)classes

2010-04-25 Thread Mihail Strashun
On 04/25/2010 04:47 PM, Joseph Wakeling wrote: Robert Clipsham wrote: This should do what you want: Thanks! :-) Is it possible to do this with an interface instead of a base class? I'm not familiar with how the former work ... Best wishes, -- Joe

Re: Arrays of many different (sub)classes

2010-04-25 Thread Robert Clipsham
On 25/04/10 14:47, Joseph Wakeling wrote: Robert Clipsham wrote: This should do what you want: Thanks! :-) Is it possible to do this with an interface instead of a base class? I'm not familiar with how the former work ... Best wishes, -- Joe Yes it is, providing the base doesn't impl

Re: Arrays of many different (sub)classes

2010-04-25 Thread Ali Çehreli
Robert Clipsham wrote: > interface I > { > int foobar(); > // The following line will cause an error when uncommented, as > // you cannot implement methods in an interface > // void baz() {} > } Just to be complete: interfaces can have static or final functions in D2: static void ba