Instantiation issue


I have

data class Vec3i(
  override var x: Int = 0,
  override var y: Int = 0,
  override var z: Int = 0
) : Vec3t(x, y, z)

thas has as one secondary constructor as follow:

constructor(v: Vec3t<Number>) : this(v.x.toInt(), v.y.toInt(), v.z.toInt())


data class Vec3ub(
  override var x: Ubyte = Ubyte(0),
  override var y: Ubyte = Ubyte(0), 
  override var z: Ubyte = Ubyte(0)
) : Vec3t(x, y, z)

Where Vec3t is

abstract class Vec3t<T : Number>(
  override var x: T, 
  override var y: T, 
  open var z: T
) : Vec2t(x, y)

And Ubyte extends Number

Why can’t I instantiate a Vec3i from a Vec3ub then?



What do you mean by “can’t”? What happens if you try?


Sorry, I meant the compiler doesn’t find any suitable constructor

However, I just found out, I missed the out keyword in the constructor