www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - array of elements of various subclasses

reply spir <denis.spir gmail.com> writes:
Hello,


Say I have some subclasses of Pattern. When I try to write
	Pattern[] patterns =3D [x,y,z];
I get an error because, apparently, D types the array according to the clas=
s of z (Choice is here the type of z):

DeeMatch.d(473): Error: cannot implicitly convert expression (x) of type De=
eMatch.Pattern to DeeMatch.Choice
DeeMatch.d(473): Error: cannot implicitly convert expression (y) of type De=
eMatch.Pattern to DeeMatch.Choice
DeeMatch.d(473): Error: cannot implicitly convert expression ([(__error),(_=
_error),z]) of type Choice[] to Pattern[]

Is this interpretation correct? And what can I do?

Denis
-- -- -- -- -- -- --
vit esse estrany =E2=98=A3

spir.wikidot.com
Nov 07 2010
next sibling parent Jesse Phillips <jessekphillips+D gmail.com> writes:
spir Wrote:

 Hello,
 
 
 Say I have some subclasses of Pattern. When I try to write
 	Pattern[] patterns = [x,y,z];
 I get an error because, apparently, D types the array according to the class
of z (Choice is here the type of z):
 
 DeeMatch.d(473): Error: cannot implicitly convert expression (x) of type
DeeMatch.Pattern to DeeMatch.Choice
 DeeMatch.d(473): Error: cannot implicitly convert expression (y) of type
DeeMatch.Pattern to DeeMatch.Choice
 DeeMatch.d(473): Error: cannot implicitly convert expression
([(__error),(__error),z]) of type Choice[] to Pattern[]
 
 Is this interpretation correct? And what can I do?
 
 Denis
 -- -- -- -- -- -- --
 vit esse estrany ☣
 
 spir.wikidot.com
 
Pattern[] patterns = [x,y,cast(Pattern)z];
Nov 07 2010
prev sibling parent Don <nospam nospam.com> writes:
spir wrote:
 Hello,
 
 
 Say I have some subclasses of Pattern. When I try to write
 	Pattern[] patterns = [x,y,z];
 I get an error because, apparently, D types the array according to the class
of z (Choice is here the type of z):
 
 DeeMatch.d(473): Error: cannot implicitly convert expression (x) of type
DeeMatch.Pattern to DeeMatch.Choice
 DeeMatch.d(473): Error: cannot implicitly convert expression (y) of type
DeeMatch.Pattern to DeeMatch.Choice
 DeeMatch.d(473): Error: cannot implicitly convert expression
([(__error),(__error),z]) of type Choice[] to Pattern[]
 
 Is this interpretation correct? And what can I do?
 
 Denis
 -- -- -- -- -- -- --
 vit esse estrany ☣
 
 spir.wikidot.com
Yes, that's a known bug. It's on the to-do list.
Nov 07 2010