C++ 指向指针解引用的指针;编译器请求'-&燃气轮机';
我编写了一个简单的函数,将一个子列表插入到引用给出的链表中。代码看起来对我来说是正确的,但编译器指示我没有正确使用指针C++ 指向指针解引用的指针;编译器请求'-&燃气轮机';,c++,pointers,dereference,C++,Pointers,Dereference,我编写了一个简单的函数,将一个子列表插入到引用给出的链表中。代码看起来对我来说是正确的,但编译器指示我没有正确使用指针 void insertSub(string h, day d, string gr, string sub, ListAPI **tmp_api) { auto newNode = new _ListSub; // initialize new node of sub-list newNode->h = h; newNode->d = d; n
void insertSub(string h, day d, string gr, string sub, ListAPI **tmp_api) {
auto newNode = new _ListSub;
// initialize new node of sub-list
newNode->h = h;
newNode->d = d;
newNode->gr = gr;
newNode->sub = sub;
// point new node to the previous and next node
newNode->next = node->next;
newNode->prev = node;
// point actual node to the new node
*tmp_api->head->next->prev = newNode;
*tmp_api->head->next = newNode;
cout << "New node inserted to " << *tmp_api->id << endl;
// increment size
++ node->size;
}
其中api
属于ListAPI*
类型,并且不包含节点
g++错误:
../src/main.cpp:107:13: error: request for member ‘head’ in ‘* tmp_api’, which is of pointer type ‘ListAPI*’ (maybe you meant to use ‘->’ ?)
*tmp_api->head->next->prev = newNode;
^~~~
../src/main.cpp:108:13: error: request for member ‘head’ in ‘* tmp_api’, which is of pointer type ‘ListAPI*’ (maybe you meant to use ‘->’ ?)
*tmp_api->head->next = newNode;
^~~~
../src/main.cpp:110:51: error: request for member ‘id’ in ‘* tmp_api’, which is of pointer type ‘ListAPI*’ (maybe you meant to use ‘->’ ?)
cout << " $ newNode inserted to " << *tmp_api->id << endl;
。/src/main.cpp:107:13:错误:请求“*tmp_api”中的成员“head”,该成员是指针类型“ListAPI*”(可能您打算使用“->”?)
*tmp_api->head->next->prev=newNode;
^~~~
../src/main.cpp:108:13:错误:请求“*tmp_api”中的成员“head”,该成员的指针类型为“ListAPI*”(可能您打算使用“->”?)
*tmp_api->head->next=newNode;
^~~~
../src/main.cpp:110:51:错误:请求“*tmp_api”中的成员“id”,该成员的指针类型为“ListAPI*”(可能您打算使用“->”?)
cout如图所示,->
运算符的优先级高于*
运算符,因此首先对其求值。使用(*temp\u api)->head
如图所示,->
运算符的优先级高于*
运算符,因此首先对其进行评估。使用(*temp\u api)->head
我们需要了解您如何定义ListAPI
,但是head
将成为结构的成员似乎有些奇怪。建议:将代码与以下示例进行比较:。您有运算符优先级问题。编写(*tmp_-api)->head
我们需要了解您如何定义ListAPI
,但head
将成为结构的成员似乎有些奇怪。建议:将代码与以下示例进行比较:。您有运算符优先级问题。写(*tmp\u api)->头
../src/main.cpp:107:13: error: request for member ‘head’ in ‘* tmp_api’, which is of pointer type ‘ListAPI*’ (maybe you meant to use ‘->’ ?)
*tmp_api->head->next->prev = newNode;
^~~~
../src/main.cpp:108:13: error: request for member ‘head’ in ‘* tmp_api’, which is of pointer type ‘ListAPI*’ (maybe you meant to use ‘->’ ?)
*tmp_api->head->next = newNode;
^~~~
../src/main.cpp:110:51: error: request for member ‘id’ in ‘* tmp_api’, which is of pointer type ‘ListAPI*’ (maybe you meant to use ‘->’ ?)
cout << " $ newNode inserted to " << *tmp_api->id << endl;