digitalmars.D - Array of interfaces static initialization
- Yossarian (26/26) Apr 18 2008 Hello.
- Janice Caron (3/4) Apr 18 2008 I think it should be
- Yossarian (8/12) Apr 18 2008 And what if the command object has overloaded opCast() operator? The
- Janice Caron (3/5) Apr 18 2008 iObject temp = c;
- Yossarian (9/14) Apr 18 2008 I know that this is working, I used it as an hack, but it is exactly tha...
- Steven Schveighoffer (14/36) Apr 18 2008 Not so badly :) Basically, the expression [c, this] is ambiguous to the...
Hello. I've got following array: typedef iObject[] paramList; and following object architecture: abstract class iObject { ... }; class associativeArray : iObject { ... }; class block : iObject { ... }; class cIrc : block { ... }; class command : associativeArray { ... }; and have function Run(paramList); .. when I use (z.B.) command c; cIrc this; Run([c, this]); irc.d(278): Error: cannot implicitly convert expression (this) of type ghhd.irc. cIrc to ghhd.irc.command both command and irc could be easily upcast to iObject, so I think that this is absolutely legal usage (bug ?), or I've badly understood the array initializer? TIA -- Yossarian Tato zpráva byla vytvořena převratným poštovním klientem Opery: http://www.opera.com/mail/
Apr 18 2008
On 18/04/2008, Yossarian <xtauer01 stud.fit.vutbr.cz> wrote:Run([c, this]);I think it should be Run([cast(iObject)c,this]);
Apr 18 2008
Dne Fri, 18 Apr 2008 20:26:34 +0200 Janice Caron <caron800 googlemail.com> napsal/-a:On 18/04/2008, Yossarian <xtauer01 stud.fit.vutbr.cz> wrote:And what if the command object has overloaded opCast() operator? The explicit upcasts are forbidden then? TIA -- Yossarian Tato zpráva byla vytvořena převratným poštovním klientem Opery: http://www.opera.com/mail/Run([c, this]);I think it should be Run([cast(iObject)c,this]);
Apr 18 2008
On 18/04/2008, Yossarian <xtauer01 stud.fit.vutbr.cz> wrote:And what if the command object has overloaded opCast() operator? The explicit upcasts are forbidden then?iObject temp = c; Run([temp,this]);
Apr 18 2008
Dne Fri, 18 Apr 2008 20:49:37 +0200 Janice Caron <caron800 googlemail.com> napsal/-a:On 18/04/2008, Yossarian <xtauer01 stud.fit.vutbr.cz> wrote:I know that this is working, I used it as an hack, but it is exactly that I dont want to . :-) Never mind, hope I won't need to read that code again. Thank you all. -- Tato zpráva byla vytvořena převratným poštovním klientem Opery: http://www.opera.com/mail/And what if the command object has overloaded opCast() operator? The explicit upcasts are forbidden then?iObject temp = c; Run([temp,this]);
Apr 18 2008
"Yossarian" wroteHello. I've got following array: typedef iObject[] paramList; and following object architecture: abstract class iObject { ... }; class associativeArray : iObject { ... }; class block : iObject { ... }; class cIrc : block { ... }; class command : associativeArray { ... }; and have function Run(paramList); .. when I use (z.B.) command c; cIrc this; Run([c, this]); irc.d(278): Error: cannot implicitly convert expression (this) of type ghhd.irc. cIrc to ghhd.irc.command both command and irc could be easily upcast to iObject, so I think that this is absolutely legal usage (bug ?), or I've badly understood the array initializer?Not so badly :) Basically, the expression [c, this] is ambiguous to the compiler. So it makes a decision and says whatever the type of the first element is the type of the array. So it types this as command[2]. Then it can't implicitly convert cIrc to command automatically so it pukes. Janice's solution tells the compiler how to declare the literal (as an iObject[]) What you don't realize is that the D language is structured to have context-free parsing, which means just because [c, this] is used as an argument to Run, which takes iObject[], doesn't matter. The compiler looks at [c, this] without context and tries to determine the type just from those tokens. This makes the compiler implementation much simpler, but makes the compiler less 'intuitive.' -Steve
Apr 18 2008