digitalmars.D.bugs - Arrays of interfaces
- Mike Parker (14/14) Jun 15 2004 I know casting from an array of classes to an array of interfaces is not...
- Ivan Senji (4/18) Jun 15 2004 Are you sure? I tried this (now and before) and it works.
- Mike Parker (13/15) Jun 15 2004 I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments:
- Regan Heath (6/22) Jun 15 2004 This compiles for me too dmd 0.92 Windows.
- Derek (21/42) Jun 15 2004 Whoa!! I am really misunderstanding Interfaces. What does an array of
- Mike Parker (8/44) Jun 15 2004 class Keyboard : EventGenerator { }
- Derek Parnell (101/146) Jun 15 2004 Okay, didn't know you could do that! Neat. I played around with this ide...
- J Anderson (5/9) Jun 16 2004 Its called polymorphism and its one of the cornerstones of object
- Derek (8/18) Jun 16 2004 Hey, I know polymorphism. Its just that I didn't know one could use an
- Matthew (6/21) Jun 16 2004 Ha! Punched cards. You lived in luxury. We only had open connections for...
- Kris (9/32) Jun 16 2004 idea
- J Anderson (5/44) Jun 16 2004 Reminds me of a futuristic movie I once saw. What was it called now? Oh...
- Mike Parker (4/25) Jun 15 2004 Ahem. Not a D bug. The error was actually one line below the one I was
- Ivan Senji (3/28) Jun 16 2004 Don't do that, it happens :)
I know casting from an array of classes to an array of interfaces is not allowed, but IMO this should be: ******************************************* interface MyInterface { ... } MyInterface[] interfaceArray; ******************************************* The compiler spits out: no [] overload for type MyInterface Doing this: MyInterface[4] interfaceArray; Yields this message: '4' is not an lvalue Bug or not?
Jun 15 2004
"Mike Parker" <aldacron71 yahoo.com> wrote in message news:cank2k$3nm$1 digitaldaemon.com...I know casting from an array of classes to an array of interfaces is not allowed, but IMO this should be: ******************************************* interface MyInterface { ... } MyInterface[] interfaceArray; ******************************************* The compiler spits out: no [] overload for type MyInterfaceAre you sure? I tried this (now and before) and it works. At least on dmd 0.92.Doing this: MyInterface[4] interfaceArray; Yields this message: '4' is not an lvalue Bug or not?
Jun 15 2004
Ivan Senji wrote:Are you sure? I tried this (now and before) and it works. At least on dmd 0.92.I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments: ****************************************** interface EventGenerator { public: void frame(); } private EventGenerator[] generators; ****************************************** I've tried it without the access modifiers, without the method declaration, moving the brackets... it keeps spitting out the same errors.
Jun 15 2004
On Wed, 16 Jun 2004 06:31:39 +0900, Mike Parker <aldacron71 yahoo.com> wrote:Ivan Senji wrote:This compiles for me too dmd 0.92 Windows. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/Are you sure? I tried this (now and before) and it works. At least on dmd 0.92.I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments: ****************************************** interface EventGenerator { public: void frame(); } private EventGenerator[] generators; ****************************************** I've tried it without the access modifiers, without the method declaration, moving the brackets... it keeps spitting out the same errors.
Jun 15 2004
On Wed, 16 Jun 2004 06:31:39 +0900, Mike Parker wrote:Ivan Senji wrote:Whoa!! I am really misunderstanding Interfaces. What does an array of interfaces give one? I thought that an interface was a type of instruction to the compiler and didn't, in itself, generate any machine code. I think of them as a set of items that when placed in a class definition, is telling the compiler that these items are mandatory for this class. That is, that these items must be defined for the class. One can't instantiate an interface object. You can't do ... class Foo: generators[2] { . . . } class Bar: generators[4] { . . . } I'm obviously missing something important here. -- Derek Melbourne, AustraliaAre you sure? I tried this (now and before) and it works. At least on dmd 0.92.I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments: ****************************************** interface EventGenerator { public: void frame(); } private EventGenerator[] generators; ****************************************** I've tried it without the access modifiers, without the method declaration, moving the brackets... it keeps spitting out the same errors.
Jun 15 2004
Derek wrote:On Wed, 16 Jun 2004 06:31:39 +0900, Mike Parker wrote:class Keyboard : EventGenerator { } class Mouse : EventGenerator { } registerGenerator(mouseObject); registerGenerator(keyboardObject); The registerGenerator method should be able to store any EventGenerator implementations in an array of EventGenerators. That's what one gets from an array of interfaces.Ivan Senji wrote:Whoa!! I am really misunderstanding Interfaces. What does an array of interfaces give one? I thought that an interface was a type of instruction to the compiler and didn't, in itself, generate any machine code. I think of them as a set of items that when placed in a class definition, is telling the compiler that these items are mandatory for this class. That is, that these items must be defined for the class. One can't instantiate an interface object.Are you sure? I tried this (now and before) and it works. At least on dmd 0.92.I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments: ****************************************** interface EventGenerator { public: void frame(); } private EventGenerator[] generators; ****************************************** I've tried it without the access modifiers, without the method declaration, moving the brackets... it keeps spitting out the same errors.
Jun 15 2004
On Wed, 16 Jun 2004 07:57:58 +0900, Mike Parker wrote:Derek wrote:Okay, didn't know you could do that! Neat. I played around with this idea and got this... // ----------------- start code import std.c.stdio; interface EventGenerator { public: int frame(); void frame(int pVal); } interface ObjType { public: char[] objType(); } class Keyboard : EventGenerator, ObjType { private: int id = -1; public: int frame() { return id;} char[] objType() { return "keyboard"; } void frame(int pVal){ if (pVal >= 0) id = pVal; } } class Mouse : EventGenerator, ObjType { private: int id = -1; public: int frame() { return id;} char[] objType() { return "mouse"; } void frame(int pVal){ if (pVal >= 0) id = pVal; } } class DupException { private char[] MsgText; this(char[] pMsg) { MsgText = pMsg; } char[] Msg() { return MsgText; } } private EventGenerator[] generators; void registerGenerator(EventGenerator x) { if (x.frame < 0) { x.frame = generators.length + 1; generators ~= x; } else { char[] buffer; buffer.length = 256; _snprintf(buffer, 256, "Duplicate generator. Frame is %d",x.frame); throw new DupException(buffer); } } void main() { Keyboard keyboardObject = new Keyboard; Mouse mouseObject = new Mouse; printf("%.*s pre-reg id = %d\n", keyboardObject.objType, keyboardObject.frame()); printf("%.*s pre-reg id = %d\n", mouseObject.objType, mouseObject.frame()); try{ registerGenerator(mouseObject); registerGenerator(keyboardObject); //registerGenerator(mouseObject); } catch (DupException x) { printf("ERROR: %.*s\n", x.Msg); printf("Number registered: %d\n", generators.length); return; } for (int i = 0; i < generators.length; i++) { int id; char[] t; id = generators[i].frame(); if (mouseObject.frame == id) t = mouseObject.objType; else if (keyboardObject.frame == id) t = keyboardObject.objType; }; printf("%.*s post-reg id = %d\n", keyboardObject.objType, keyboardObject.frame()); printf("%.*s post-reg id = %d\n", mouseObject.objType, mouseObject.frame()); }// -----------------end code -- Derek Melbourne, Australia 16/Jun/04 10:57:43 AMOn Wed, 16 Jun 2004 06:31:39 +0900, Mike Parker wrote:class Keyboard : EventGenerator { } class Mouse : EventGenerator { } registerGenerator(mouseObject); registerGenerator(keyboardObject); The registerGenerator method should be able to store any EventGenerator implementations in an array of EventGenerators. That's what one gets from an array of interfaces.Ivan Senji wrote:Whoa!! I am really misunderstanding Interfaces. What does an array of interfaces give one? I thought that an interface was a type of instruction to the compiler and didn't, in itself, generate any machine code. I think of them as a set of items that when placed in a class definition, is telling the compiler that these items are mandatory for this class. That is, that these items must be defined for the class. One can't instantiate an interface object.Are you sure? I tried this (now and before) and it works. At least on dmd 0.92.I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments: ****************************************** interface EventGenerator { public: void frame(); } private EventGenerator[] generators; ****************************************** I've tried it without the access modifiers, without the method declaration, moving the brackets... it keeps spitting out the same errors.
Jun 15 2004
Derek Parnell wrote:On Wed, 16 Jun 2004 07:57:58 +0900, Mike Parker wrote: Okay, didn't know you could do that! Neat. I played around with this idea and got this...Its called polymorphism and its one of the cornerstones of object orientation. -- -Anderson: http://badmama.com.au/~anderson/
Jun 16 2004
On Wed, 16 Jun 2004 17:31:56 +0800, J Anderson wrote:Derek Parnell wrote:Hey, I know polymorphism. Its just that I didn't know one could use an interface as a 'property' of a class. I've not worked with modern OOP autocoder with these new-fangled punched card thingies. ;-) -- Derek Melbourne, AustraliaOn Wed, 16 Jun 2004 07:57:58 +0900, Mike Parker wrote: Okay, didn't know you could do that! Neat. I played around with this idea and got this...Its called polymorphism and its one of the cornerstones of object orientation.
Jun 16 2004
"Derek" <derek psyc.ward> wrote in message news:3jr7u6r232a8$.1791r062spmxc$.dlg 40tude.net...On Wed, 16 Jun 2004 17:31:56 +0800, J Anderson wrote:Ha! Punched cards. You lived in luxury. We only had open connections for a 4-bit bus, and we had to set the bits by connecting live plugs them with conductive surfaces from our own bodies! Suffice to say you tried to avoid any codes involving the number 15 ...Derek Parnell wrote:Hey, I know polymorphism. Its just that I didn't know one could use an interface as a 'property' of a class. I've not worked with modern OOP autocoder with these new-fangled punched card thingies. ;-)On Wed, 16 Jun 2004 07:57:58 +0900, Mike Parker wrote: Okay, didn't know you could do that! Neat. I played around with this idea and got this...Its called polymorphism and its one of the cornerstones of object orientation.
Jun 16 2004
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:caqiuk$1inp$1 digitaldaemon.com..."Derek" <derek psyc.ward> wrote in message news:3jr7u6r232a8$.1791r062spmxc$.dlg 40tude.net...ideaOn Wed, 16 Jun 2004 17:31:56 +0800, J Anderson wrote:Derek Parnell wrote:On Wed, 16 Jun 2004 07:57:58 +0900, Mike Parker wrote: Okay, didn't know you could do that! Neat. I played around with this4-bitHa! Punched cards. You lived in luxury. We only had open connections for aHey, I know polymorphism. Its just that I didn't know one could use an interface as a 'property' of a class. I've not worked with modern OOP autocoder with these new-fangled punched card thingies. ;-)and got this...Its called polymorphism and its one of the cornerstones of object orientation.bus, and we had to set the bits by connecting live plugs them withconductivesurfaces from our own bodies! Suffice to say you tried to avoid any codes involving the number 15 ...You still 'ad body parts? Ooohhh, we use t' dreeeeaammmm o' body parts. Wor fingers and skin 'ad all been 'acked off t' use for printer 'eads n' cable wrap. An' wor testicles ended up in t' abacus ... 4-bit bus? Huh! You were Lucky!!
Jun 16 2004
Kris wrote:"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:caqiuk$1inp$1 digitaldaemon.com...Reminds me of a futuristic movie I once saw. What was it called now? Oh the matrix. -- -Anderson: http://badmama.com.au/~anderson/"Derek" <derek psyc.ward> wrote in message news:3jr7u6r232a8$.1791r062spmxc$.dlg 40tude.net...4-bitOn Wed, 16 Jun 2004 17:31:56 +0800, J Anderson wrote: Hey, I know polymorphism. Its just that I didn't know one could use an interface as a 'property' of a class. I've not worked with modern OOP autocoder with these new-fangled punched card thingies. ;-)Ha! Punched cards. You lived in luxury. We only had open connections for abus, and we had to set the bits by connecting live plugs them withconductivesurfaces from our own bodies! Suffice to say you tried to avoid any codes involving the number 15 ...You still 'ad body parts? Ooohhh, we use t' dreeeeaammmm o' body parts. Wor fingers and skin 'ad all been 'acked off t' use for printer 'eads n' cable wrap. An' wor testicles ended up in t' abacus ... 4-bit bus? Huh! You were Lucky!!
Jun 16 2004
Mike Parker wrote:Ivan Senji wrote:Ahem. Not a D bug. The error was actually one line below the one I was looking at, and was indeed a mistake on my part (typo). I will go stick my head in a hole-in-the-ground now.Are you sure? I tried this (now and before) and it works. At least on dmd 0.92.I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments: ****************************************** interface EventGenerator { public: void frame(); } private EventGenerator[] generators; ******************************************
Jun 15 2004
"Mike Parker" <aldacron71 yahoo.com> wrote in message news:cao09l$lbt$1 digitaldaemon.com...Mike Parker wrote:Don't do that, it happens :)Ivan Senji wrote:Ahem. Not a D bug. The error was actually one line below the one I was looking at, and was indeed a mistake on my part (typo). I will go stick my head in a hole-in-the-ground now.Are you sure? I tried this (now and before) and it works. At least on dmd 0.92.I'm sure. dmd 0.92 on Windows. Here's my exact code sans comments: ****************************************** interface EventGenerator { public: void frame(); } private EventGenerator[] generators; ******************************************
Jun 16 2004