这是我用于检查平衡括号的代码,它接受一个表达式并检查用户是否正确输入了表达式但它不起作用。它给出了一个错误。我不认为公共(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/