Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;编译器错误 我写了一个C++栈和队列实现程序,我完成了栈部分,但是编译时我得到这些错误 arrayListImp.cpp:18:19: error: expected unqualified-id arrayList[++top]= x; ^ arrayListImp.cpp:28:13: error: 'arrayList' does not refer to a value itemPoped=arrayList[top]; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ arrayListImp.cpp:35:9: error: 'arrayList' does not refer to a value return arrayList[top]; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ arrayListImp.cpp:46:9: error: 'arrayList' does not refer to a value cout<<arrayList[i]<<endl; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ 4 errors generated._C++ - Fatal编程技术网

C++;编译器错误 我写了一个C++栈和队列实现程序,我完成了栈部分,但是编译时我得到这些错误 arrayListImp.cpp:18:19: error: expected unqualified-id arrayList[++top]= x; ^ arrayListImp.cpp:28:13: error: 'arrayList' does not refer to a value itemPoped=arrayList[top]; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ arrayListImp.cpp:35:9: error: 'arrayList' does not refer to a value return arrayList[top]; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ arrayListImp.cpp:46:9: error: 'arrayList' does not refer to a value cout<<arrayList[i]<<endl; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ 4 errors generated.

C++;编译器错误 我写了一个C++栈和队列实现程序,我完成了栈部分,但是编译时我得到这些错误 arrayListImp.cpp:18:19: error: expected unqualified-id arrayList[++top]= x; ^ arrayListImp.cpp:28:13: error: 'arrayList' does not refer to a value itemPoped=arrayList[top]; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ arrayListImp.cpp:35:9: error: 'arrayList' does not refer to a value return arrayList[top]; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ arrayListImp.cpp:46:9: error: 'arrayList' does not refer to a value cout<<arrayList[i]<<endl; ^ ./arrayList.h:3:7: note: declared here class arrayList{ ^ 4 errors generated.,c++,C++,arrayListImp.cpp #include <iostream> #include "arrayList.h" using namespace std; //Stack implementation stack::stack(){ top = -1; } void stack::push(int x){ if (top == maxSize -1){ cout<<"Stack overflow"<<endl;

arrayListImp.cpp

#include <iostream>
#include "arrayList.h"
using namespace std;

//Stack implementation

stack::stack(){

    top = -1;
}

void stack::push(int x){

    if (top == maxSize -1){
        cout<<"Stack overflow"<<endl;
    }
    else{
        arrayList[++top]= x;
        cout<<x<<", is pushed on to the stack"<<endl;
    }
}

void stack::pop(){
    if (top == -1){
        cout<<"Stack underflow"<<endl;
    }
    else{
        itemPoped=arrayList[top];
        top--;
        cout<<itemPoped<<", is poped from the stack"<<endl; 
    }
}

int stack::Top(){
    return arrayList[top];
}

int stack::isEmpty(){
    if (top == -1) return 1;
    return 0;
}

void stack::print(){
    cout<<"Stack: "<<endl;
    for (i = 0; i<=top; i++){
        cout<<arrayList[i]<<endl;

    }
}
#包括
#包括“arrayList.h”
使用名称空间std;
//堆栈实现
stack::stack(){
top=-1;
}
void stack::push(int x){
if(top==maxSize-1){

难道你一直都在写信吗

arrayList[...]
你的类的名称是什么,但是在阅读代码时,你似乎想编写它

array[...]

它将访问数据。

您只需阅读错误消息即可

  • 您应该使用
    array
    而不是
    arrayList
    ,后者是类的名称。因此只需引用变量即可

    您收到的错误消息类似于

    test.cpp: In member function ‘void stack::push(int)’:
    test.cpp:44:18: error: expected unqualified-id before ‘[’ token
             arrayList[++top]= x;
                      ^
    
    /tmp/cc4y06YN.o:test.cpp:function stack::stack(): error: undefined reference to 'arrayList::arrayList()'
    
    当你检查线路时,你会立即看到哪里出了问题

  • 您声明了一个构造函数
    arrayList::arrayList()
    ,但没有定义它。您可以删除该声明,或者应该在cpp文件中实现它

    arrayList::arrayList() {
        // do some initialization
    }
    
    您收到的错误消息类似于

    test.cpp: In member function ‘void stack::push(int)’:
    test.cpp:44:18: error: expected unqualified-id before ‘[’ token
             arrayList[++top]= x;
                      ^
    
    /tmp/cc4y06YN.o:test.cpp:function stack::stack(): error: undefined reference to 'arrayList::arrayList()'
    
    代码可以编译,但没有链接。因此,所有声明都可能是正确的,但缺少一个符号。通常情况下,当您声明了所引用的内容,但从未定义它时,就会出现这种情况


  • arrayList[++top]
    ->
    arrayList[++top]
    对我来说似乎是一个打字错误。感谢我没有注意到这一点。错误现在已经消失了,但我得到了这个错误
    架构x86的未定义符号。\u 64:“arrayList::arrayList()”,引用自ArrayListP-c791dd.o ld:symbol中的:stack::stack()找不到架构x86_64 clang的链接器命令:错误:链接器命令失败,退出代码为1(使用-v查看调用)
    您没有实现arrayList::arrayList()。它只是在标头中声明,但没有定义