Dynamic Vector of objects
I'm trying to create a dynamic vector of struct objects but facing this error:
error: 'DynamicVector' parameter #0 has 'CollectionElement' type, but value has type 'MyPair'
var vector = DynamicVector[MyPair] ()
I've also tried creating a copy and move constructor but still facing the same problem
Here is my code:
2 Replies
Got it!
Had to do this:
struct MyPair(CollectionElement):
In this code, MyPair is declared to implement the CollectionElement trait by adding it in parentheses after the struct name. This tells the compiler that MyPair meets the requirements of the CollectionElement trait, which includes having a copy constructor (copyinit), a move constructor (moveinit), and a destructor (del)
Congrats @taalhaataahir01022001, you just advanced to level 5!