这个C ++映射有什么问题? [英] What is wrong with this C++ map?
本文介绍了这个C ++映射有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想能够通过文本字符串调用特定的矩阵。我试图设置一个地图来做到这一点,但我没有很好的。
I would like to be able to call specific matrices by a text string. I am trying to set up a map to do this, but I do not have it quite right.
我注意到,如果我引用矩阵我试图操纵通过它的映射名称,它似乎工作(即, signalIndex [T2]。signal [i] [0] = 10)
,但是如果我尝试引用地图标签指向的矩阵,它不工作。有任何建议吗?
I notice that if I refer to the matrix I am trying to manipulate by its map name, it seems to work (i.e., signalIndex["T2"].signal[i][0]=10)
, however if I try to refer to the matrix that the map label is pointing to, it does not work. Any suggestions?
#include <iostream>
#include <map>
using namespace std;
struct signalGrid{
double signal[20][200];
signalGrid();
};
void mapTest(std::map<string,signalGrid> &temp_map);
map<string,signalGrid> signalIndex;
signalGrid testGrid1,testGrid2;
int main(){
int i;
signalGrid tempGrid;
mapTest(signalIndex);
tempGrid=signalIndex["T1"];
for(i=0;i<5;i++){
tempGrid.signal[i][0]=5;}
for(i=0;i<5;i++){
cout<<"TEST="<<tempGrid.signal[i][0]<<"\n";}
for(i=0;i<5;i++){
cout<<"TEST="<<testGrid1.signal[i][0]<<"\n";}
for(i=0;i<5;i++){
cout<<"TEST2="<<signalIndex["T1"].signal[i][0]<<"\n";}
for(i=0;i<5;i++){
signalIndex["T2"].signal[i][0]=10;}
for(i=0;i<5;i++){
cout<<"TEST3="<<testGrid2.signal[i][0]<<"\n";}
for(i=0;i<5;i++){
cout<<"TEST4="<<signalIndex["T2"].signal[i][0]<<"\n";}
return 0;
}
void mapTest(std::map<string,signalGrid> &temp_map){
temp_map["T1"]=testGrid1;
temp_map["T2"]=testGrid2;
return;
}
signalGrid::signalGrid(){
int i,j;
for(i=0;i<20;i++){
for(j=0;j<200;j++){
signal[i][j]=0;}}
}
推荐答案
tempGrid=signalIndex["T1"];
修改tempGrid不会更新映射中的相应矩阵
modifiying tempGrid won't update the corresponding matrix in the map
这篇关于这个C ++映射有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文