首页 \ 问答 \ 为什么vector :: iterator有效并且vector * :: iterator不是?(Why is vector::iterator valid and vector*::iterator not?)

为什么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
更新时间:2023-01-11 08:01

最满意答案

你可以映射到元组,但是如果你把你的项目放在列表中:

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 +: _ = ....

相关问答

更多
  • 只需要替换列表中的元组; 只要避免添加或删除元素,您可以在循环时更改列表: 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 ...
  • 由于您是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和Tuples的内容吗? 我认为Odersky试图表明的主要观点是每个元组元素都可以包含自己的单独类型,这允许使用多种不同的类型。 由于列表是同类的,因此List无法执行的操作,这意味着如果您需要List[Int] ,则该列表的所有元素都必须是Int值。 如果查看您创建的列表的类型,您将看到编译器推断List[Any] ,这是所有Scala类型的常见超类型。 这意味着如果你想用列表中的一个元素做一些具体的事情,即它是Int类型的head元素,你不能因为所有编译器都知道该 ...
  • 只是: 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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。