结构回推不起作用
Structure Push back not working
#include<cstdio>
#include<vector>
using namespace std;
struct Edge
{
int from;
int to;
int weight;
};
int main()
{
vector<Edge> v;
v.push_back(Edge (1,2,10));
v.push_back(Edge (2,3,30));
v.push_back(Edge (1,3,20));
return 0;
}
为什么push_back函数在向量中不起作用并给出错误? 如何直接在 vector 中插入值而不定义 Edge 类型的变量?
除了注释中提供的答案外,您还可以简单地在结构中添加构造函数。
Edge(int f, int t, int w) {
from = f;
to = t;
weight = w;
}
相关文章:
- 编译器上的策略数据结构不起作用
- C++结构模板变量快捷方式定义不起作用
- 内部结构初始化不起作用 - C++
- 没有类型结构绑定不起作用?
- 使用选择排序对数组数据结构进行排序,但它不起作用
- 结构/方法不起作用
- 如果在结构内部使用condition_variable,则它不起作用
- C++覆盖父结构中的数据不起作用
- 将参考类型作为嵌套模板结构中的模板参数作为模板参数不起作用
- 指向结构的指针不起作用
- 结构程序不起作用
- GCC:当层次结构中存在虚拟继承时,C++11 内联对象初始化(使用 "this")不起作用
- C++ -- 指向结构数组的指针,该数组包含指向不起作用的类数组的指针
- 如果所述结构具有构造函数,则带有 new[] 的结构数组似乎不起作用
- 在文档中引用使用doxygen的结构成员不起作用;结构成员未出现在文档中
- 为什么我的结构中映射的构造函数不起作用
- 我的火狐扩展程序不起作用。使用C++XPCOM组件的Firefox扩展(XPI文件)的结构是什么?
- c++ 将文本文件读取到结构数组中不起作用
- 从存储在 CTreeCtrl 的 LPARAM 中的结构中检索地址/指针 (IXMLDOMNode*) - 不起作用
- 自定义结构排序不起作用