要制作加权的多图,我会做以下事情
#include <iostream>
#include <vector>
using namespace std;
struct maps
{
vector<char> weight(10); //to store weight of self-loops and multi-edges
};
int main()
{
maps m1[101][101], m2[101][101];
return 0;
}
但我收到以下错误:
error: expected identifier before numeric constant
error: expected ‘,’ or ‘...’ before numeric constant
我该如何解决这个问题?
答案 0 :(得分:3)
正如Ade YU所提到的,不要在声明中定义你的权重向量的大小。相反,在构造函数的初始化列表中执行此操作。这应该做你想要的:
#include <iostream>
#include <vector>
using namespace std;
struct maps
{
maps() : weight(10) {}
vector<char> weight; //to store weight of self-loops and multi-edges
};
int main()
{
maps m1[101][101], m2[101][101];
return 0;
}
答案 1 :(得分:0)
您需要在构造函数中初始化向量。试试这个:
#include <iostream>
#include <vector>
using namespace std;
struct maps{
maps() : weight(10) {}
vector<char> weight;//to store weight of self-loops and multi-edges
};
int main()
{
maps m1[101][101], m2[101][101];
return 0;
}