将 forward_list::p ush_front() 与结构对象一起使用
Using forward_list::push_front() with a struct object
我想开始使用STL版本的单链表,但我遇到了一个问题。如果我希望我的列表由结构类型对象组成,而不仅仅是简单的本机类型,如 int、char 等,我对如何使用 push_front() 函数有一个两难的选择,因为它只需要一个参数。那么我如何使用这样的代码插入新对象:
#include <iostream>
#include <forward_list>
using namespace std;
struct Node
{
double x;
double y;
};
int main()
{
forward_list<Node> myList;
myList.push_front(???);
}
???我感谢给予的任何帮助!!
myList.push_front({3.14, 2.71});
, myList.push_front(Node{3.14, 2.71});
和
Node n;
n.x = 3.14;
n.y = 2.71;
myList.push_front(n);
应该都工作。例。
相关文章:
- 为什么我们再次从结构对象创建结构变量?
- 在什么情况下,两个堆栈分配的结构对象的 this 点指向同一个地址?
- 结构对象的指针成员在传递给函数时被修改
- C++ 提升 - 包含类层次结构对象的类的序列化
- 如何将变量从变量传递到指针结构对象
- 在 boost::heap::p riority_queue 中推送结构对象时出错
- 在 c++ 中将结构的每个成员写入文件和将结构对象直接写入文件之间有什么区别吗?
- 为什么结构对象不是类型?
- 程序不会编译,使用带有结构对象的数组
- 在类构造函数中初始化自定义结构对象的正确方法
- 使用QString或字符串调用结构对象
- 在输入结构对象的输入过程中运行时间错误
- C 中的堆是否包含类和结构对象,或者仅包含指针
- 如何将部分初始化的结构对象放入向量
- 如何分配给结构对象的成员
- 尝试创建结构对象,在位置0x3FE00000中创建访问冲突写入错误
- erase() 不适用于结构/对象内的 STL 向量
- 将指向参数个数可变的函数的指针存储在结构对象中
- 如何通过先前存储的ID从结构对象中检索值?C
- 非结构对象布局