Phoenix, it would be appreciated if you didn't try to start debates around your
political positions (otherwise, why mention them). That would be neither
productive to the discussion, nor give you any helpful replies, other than
annoy people.
Yes, it's from my dear Delphi, from which, i'm noticing more and more, nim took
a lot, including the result variable! That's good. But even if it was from
89's' pascal, what's wrong with that? Why should i always comply to some new
programming FASHION "imposed" by others? And this goes beyond th
> PS: don't prefix types with T this is not 1989 pascal :P
The `T` prefix comes from Delphi, not 89's pascal. :P
Well direct casting is unsafe and is to be avoided especially for generics. If
the program flow allows it's best to just write.
var myVideo = TVideo()
var myVideoList = @[TMedia myVideo] # No need to cast when it's not a video
list
setNewDims(myVideoList)
Run
Ah sorry ±6 years
I was so taken by this object oriented stuff that i didn't consider the most
obvious solution, CASTING. Anyway the last part of your answer, declaring the
seq as TMedia and then adding specialized classes is really neat. I'll use this
solution from now on. Thank you
Hello,
Although using generics works, this is not the only solutions, you could also
use explicit casting, like that :
var myVideo = TVideo()
var myVideoList = @[myVideo]
setNewDims(cast[seq[TMedia]](myVideoList))
Run
If you use generics, it can be a good prac
Often the answer comes after i already posted the problem. I was searching and
came across generics, so it's really simple
proc setNewDims[T](arr:seq[T])=
echo arr[0].id
Run
It works!
I have this object hierarchy with some fields :
TMedia* = ref object of RootRef
TVideo* = ref object of TMedia
TImage* = ref object of TMedia
TWebPage* = ref object of TMedia
proc setNewDims(arr:seq[TMedia])=
discard
Run
if i pass a seq[TVide