可以将矢量作为2d数组进行访问

时间:2017-04-19 19:30:17

标签: c++ vector

通过以这种方式访问​​它们,我们可以将1D数组用作2D数组: [row * width + col]

我的问题是因为向量非常相同所以我可以访问通常的向量作为2d向量吗?例如,以这种方式: [row * vector.size()+ col]

1 个答案:

答案 0 :(得分:4)

是的,但不是Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121). Type in expressions for evaluation. Or try :help. scala> case class Person(name: String, age: Int) defined class Person scala> val x = Some(Person("foo", 20)) x: Some[Person] = Some(Person(foo,20)) scala> val y = Some(("foo", 20)) y: Some[(String, Int)] = Some((foo,20)) scala> for { | a <- x.toRight("wrong").right | b <- y.toRight("wrong").right | } yield (a.name, a.age, b._1, b._2) res0: scala.util.Either[String,(String, Int, String, Int)] = Right((foo,20,foo,20)) scala> ,因为这将是元素的总数。您需要分别跟踪2D阵列的“width”

vector.size()