c++ - "Operator mismatch" error in c++
问题描述
I'm creating a transpose of the graph v
and saving it in g2
. Both v
and g2
are same type, so g2
will hold the transpose of the graph.
Below, v
is of vector<int>v[1000]
. It consists a adjacency list representation of a graph.
vector<int> v[10000] = ...; // input: some matrix
vector<int> g2[10000]; // output: transposed matrix
for(int u=0;u<N;u++) //N is the number of vertices
for(vector<int>::iterator it=v[u].begin();it!=v[u].end();it++)
g2[v[*it]].push_back(u);
I'm getting this error:
prog.cpp:74:8: error: no match for 'operator[]' (operand types are 'std::vector<int> [10001]' and 'std::vector<int>')
g2[v[*it]].push_back(u);
^
Can you guys please help me?
解决方案
vector<int> g2[10000];
for(int u=0;u<N;u++) //N is the number of vertices
{
for(vector<int>::iterator it=v[u].begin();it!=v[u].end();it++)
{
g2[u].push_back(*it);
}
}
我希望这将有所帮助。
推荐阅读
- python - 如何执行从 dis.dis() python 接收的代码?
- python-3.x - 美国 Python 请求库下载 NOAA GFS 和 CFSV2 数据
- java - 如何使用“标题”更新列表视图
- websphere - 当输入是 .rfh 文件时,如何读取我的流程数据或业务流程中的主文档中的 RFH2 标题
- node.js - 使用打字稿时在 selenium-webdriver 中找不到 WebDriverWait api
- react-native - 我对 firebase.messaging.requestPermission() 有疑问,无论我选择“允许”还是“不允许”,都会导致异常
- django - Django 数据库访问优化:高效创建多对多关系(现有对象之间)
- intellij-idea - 无法在 IntelliJ IDEA 中使用 Lombok 编译项目
- google-cloud-dataflow - GCP:数据流 [无法识别的参数]:来自 cloud-shell 的子网和来自控制台的无效值
- javascript - html中没有定义的函数