c++ - 代码不工作。使用堆栈

标签 c++

这是我用于检查平衡括号的代码,它接受一个表达式并检查用户是否正确输入了表达式但它不起作用。它给出了一个错误。我不认为公共(public)事务有错误。 请帮忙!

class dynamicStack {
    struct node{
        char num;
        node *next;
    };
    public:
    node *top;
    dynamicStack(){
        top=NULL;
    }
    void push(char);
    void pop();
    void check(string);
};

void check(string exp) {
    \\some code
}
void dynamicStack::pop(){
    node *temp;
    temp=top;
    if(top == NULL)  {
        cout<<"Stack is empty"<<endl;
    }
    else
        cout<<"Deleting number: "<<temp->num<<endl;
    top=top->next;
    delete temp;
}

void dynamicStack::push(char c) {
    node *newNode;
    newNode = new node;
    newNode->num=c;
    newNode->next=top;
    top=newNode;
}

int _tmain(int argc, _TCHAR* argv[])  {
    dynamicStack dS;
    string exp;
    cout<<"Enter an expression:  ";
    cin>>exp;
    dS.check(exp);

    system("pause");

    return 0;
}

它给出了以下错误:

     1>ds-2.obj : error LNK2019: unresolved external symbol "public: void                    _thiscall dynamicStack::check(class std::basic_string<char,struct                      std::char_traits<char>,class std::allocator<char> >)" (?    check@dynamicStack@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _wmain

最佳答案

你的实现

void check(string exp)

没有提到它的类范围。它必须是:

void dynamicStack::check(string exp) {
...
}

顺便说一句,这正是链接器消息试图告诉您的内容。当您遇到此类错误时,您通常只是犯了上述错误。

关于c++ - 代码不工作。使用堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39992571/

相关文章:

c++ - 为什么在这种情况下 lambda 没有转换为函数?

c++ - GL Buffer 设置为 GL_STATIC_DRAW 但需要发送每一帧

c++ - 用于读取音频文件的库

c++ - 涉及逻辑与 (&&) 的复杂表达式

Java JNA 解引用指针

c++ - 如何计算动态内存请求是否会导致无效分配

c++ - 为什么结构体的 sizeof 不等于每个成员的 sizeof 之和?

c++ - 如何重构容器以直接使用谓词方法?

c++ - 在VTK下保存一个Mesh文件

c++ - 将 DLL 导入 Inno Setup 时出现问题