简体   繁体   English

指向向量和数组指针的指针

[英]pointer to pointers of vector and arrays

I have a map mapping a character to a 2-d array of rules to process that character. 我有一个将字符映射到二维规则数组以处理该字符的映射。 Following is the code: 以下是代码:

struct CFG //this struct is data structure to contain a context free grammar
{
   vector<char> *V;
   vector<char> *T;
   map<char,vector<vector<rhs>*>*> *prod;
  // char start;
};

int main()
{
map<char,vector<vector<rhs>*>*> *prod;  //rhs is the type of each cell of the 2-d array
CFG cfg1;
cfg1.V= new vector<char>;

//We imput elements into the V array here......//

cfg1.prod= new map<char,vector<vector<rhs>*>*>;

for(int i=0;i<cfg1.V->size();i++)
 {
    vector<vector<rhs>*>* all_prod_of_one_nonter= new vector<vector<rhs>*>;
    *(cfg1.prod)[*(cfg1.V)[i]]=all_prod_of_one_nonter;  //error occurs here//////
 }
}

In the line, I marked as 'error occurs', the following error occurs: 在这一行中,我标记为“发生错误”,发生以下错误:

q1.cpp: In function ‘int main()’:
q1.cpp:93:29: error: no match for ‘operator*’ in ‘**(cfg1.CFG::V + ((unsigned int)(((unsigned int)i) * 12u)))’

I use * to dereference the pointer cfg1.V so that I can use subscript notation to access the array cells. 我使用*取消对指针cfg1.V的引用,以便可以使用下标表示法访问数组单元。 How to remove the error? 如何清除错误?

(*cfg1.prod)[(*cfg1.V)[i]]=all_prod_of_one_nonter;  

(原因: operator[] (数组下标)的绑定比operator* (间接)的绑定更紧密。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM