为什么vector :: iterator有效并且vector * :: iterator不是?(Why is vector::iterator valid and vector*::iterator not?)
我有三个相关的班级成员:
vector<Frame*>* poolFrames; vector<Frame*>*::iterator frameIterator; vector<vector<Frame*>::iterator>* poolFrameIterators;
当我编译时,gcc告诉我
错误:无效使用'::'错误:预期';' 'frameIterator'之前
参照中间行,我定义了frameIterators。 当我松开指向矢量的指针并使其成为vector :: iterator时,它会消失。 但是,我希望他们成为指针。 有没有特别的方法来定义我想要的数据类型,还是需要使用vector :: iterator然后解引用?
I have these three related class members:
vector<Frame*>* poolFrames; vector<Frame*>*::iterator frameIterator; vector<vector<Frame*>::iterator>* poolFrameIterators;
When I compile, gcc tells me
error: invalid use of ‘::’ error: expected ‘;’ before ‘frameIterator’
In reference to the middle line, where I define frameIterators. It goes away when I loose the pointer to the vector and make it a vector::iterator. However, I want them to be pointers. Is there a special way to define the data type that I want, or do I need to use vector::iterator and then dereference?
原文:https://stackoverflow.com/questions/3338764
最满意答案
你可以映射到元组,但是如果你把你的项目放在列表中:
val List(formatted1, formatted2, formatted3) = List(raw1, raw2, raw3).map(format)
这与许多其他集合一起工作,如Seq,Array等(两边的类型必须相同!但左边可以有更多的常规类型:例如
val Seq(...) = List(...)
)。对于列表(但不适用于其他类型),您还可以编写如下所示的内容:
val formatted1::formatted2::formatted3::Nil = List(raw1, raw2, raw3).map(format)
从Scala 2.10开始,您可以使用Seq执行相同的技巧:
val formatted +: formatted2 +: formatted3 +: _ = ....
You can map over tuple, but if you put your items in List:
val List(formatted1, formatted2, formatted3) = List(raw1, raw2, raw3).map(format)
This works with many other collections, like Seq, Array and so on (types on both sides has to be the same! but you can have more general type on the left: e.g.
val Seq(...) = List(...)
).For Lists (but not for other types) you can also write something like this:
val formatted1::formatted2::formatted3::Nil = List(raw1, raw2, raw3).map(format)
Starting from Scala 2.10 you can perform same trick with Seq:
val formatted +: formatted2 +: formatted3 +: _ = ....
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
迭代元组列表(Iterate a list of tuples)[2022-05-17]
只需要替换列表中的元组; 只要避免添加或删除元素,您可以在循环时更改列表: for i, (a, b) in enumerate(tuple_list): new_b = some_process(b) tuple_list[i] = (a, new_b) 或者,如果您可以像上面那样将b的更改汇总到函数中,请使用列表理解: tuple_list = [(a, some_process(b)) for (a, b) in tuple_list] Just replace the tuple ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
由于您是Python的新手,因此在没有太复杂的语法的情况下,这是一种简单的方法: # For each tuple inside daily_sales for sale in daily_sales: # Use the first element of that tuple as a key and check if it's inside the dictionary budgeted_sales if sale[0] in budgeted_sales: # Compare the ...
-
Scala中的列表和元组(List and Tuples in Scala)[2022-09-24]
我在这里错过了关于Scala中List和Tuples的内容吗? 我认为Odersky试图表明的主要观点是每个元组元素都可以包含自己的单独类型,这允许使用多种不同的类型。 由于列表是同类的,因此List无法执行的操作,这意味着如果您需要List[Int] ,则该列表的所有元素都必须是Int值。 如果查看您创建的列表的类型,您将看到编译器推断List[Any] ,这是所有Scala类型的常见超类型。 这意味着如果你想用列表中的一个元素做一些具体的事情,即它是Int类型的head元素,你不能因为所有编译器都知道该 ... -
从一个元组中创建一个列表(Making a list from a tuple)[2022-08-16]
只是: tuple_to_list((X, XS),[X | List]) :- tuple_to_list(XS, List). tuple_to_list((X), [X]):- X \= (_,_). 最后一个子句X \ =( , )。 因为 ?- (X) = (a,b). X = (a, b). Just : tuple_to_list((X, XS),[X | List]) :- tuple_to_list(XS, List). tuple_to_list((X), ... -
你面临的问题是你的函数不总是返回一个列表,一个数字或一个对象。 结果取决于list.length是偶数对还是奇数对。 如果可能,为了简单起见,从一个函数我总是期望相同的类型。 例如,一个名为isPalindrome的函数建议返回一个Boolean 。 def isPalindrome(x:List[Int]):Boolean = { x.equals(x.reverse) } 一旦你发现你的列表是回文,你可以打印你的结果。 if (isPalindrome(List(1,2,3,4,6))) ...
-
data = [(1, 2), (3, 4), (2, 1), (1, 2), (2, 3), (2, 3)] from collections import Counter, OrderedDict # Use Counter to find the number of times the tuple occured d = Counter(data) # Use OrderedDict to maintain the order of occurance # Get tuples from Orde ...
-
你可以映射到元组,但是如果你把你的项目放在列表中: val List(formatted1, formatted2, formatted3) = List(raw1, raw2, raw3).map(format) 这与许多其他集合一起工作,如Seq,Array等(两边的类型必须相同!但左边可以有更多的常规类型:例如val Seq(...) = List(...) )。 对于列表(但不适用于其他类型),您还可以编写如下所示的内容: val formatted1::formatted2::formatted ...
-
List#contains 是最快的方法。 它最多只能传递一次List ,并在找到匹配后立即停止。 除非您知道列表已排序,否则您无法更快地完成任务。 Scala集合库的编写方式使得所有(如果不是大多数)基本函数都针对性能进行了优化。 查看来源 。 List#contains is the fastest way to do it. It will make at most one pass of the List, and stops as soon as it finds a match. Unless ...