【发布时间】:2012-04-18 04:07:17
【问题描述】:
我正在尝试运行一个程序,但它无法编译,我得到了错误。我已经改变了一些东西,但似乎没有用。代码是这样的:
#include <iostream>
#include <string>
#include "StackLS.h"
using namespace std;
int main()
{
int answer;
char symbol;
char n, N;
StackLS stack;
bool balenced = true;
do {
cout << " ********** MENU ********** " << endl;
cout << " 1. Basic Brackets () " << endl;
cout << " 2. Standard Brackets ()[]{} " << endl;
cout << " 3. User-Defined brackets " << endl;
cout << " Please enter your choice: " << endl;
switch (answer){
case 1:
cout << "Current Setting: () " << endl;
cout << "Enter your expression followed by a ; : " << endl;
cin >> symbol;
do {
if (symbol = '(')
stack.push( '(' );
else
if (symbol = ')' )
{
if (stack.isEmpty())
balenced = false;
else {
symbol = stack.top();
stack.pop();
}
if (balenced)
cout << "Expression is well-formed" << endl;
else
cout << "Expression is not well-formed" << endl;
}
}
while (symbol != ';' && balenced);
stack.pop();
}
}
while (answer != 'n' || 'N');
} // end main
我还没有完成程序。在继续下一个案例之前,我想确保我到目前为止所拥有的内容能够编译。现在我将发布我遇到的错误。它们是:
-
1>e:\c++ language 2\well-formed expression checker solution\well-formed expression checker project\main.cpp(11): warning C4101: 'n' : unreferenced local variable
-
1>e:\c++ language 2\well-formed expression checker solution\well-formed expression checker project\main.cpp(11): warning C4101: 'N' : unreferenced local variable
-
1>e:\c++ language 2\well-formed expression checker solution\well-formed expression checker project\main.cpp(22):警告 C4700:使用了未初始化的局部变量“answer”
1>清单资源编译: 1> 所有输出都是最新的。
-
1>main.obj : 错误 LNK2019: 函数 _main 中引用的未解析的外部符号“public: int __thiscall StackLS::top(void)const” (?top@StackLS@@QBEHXZ)
1>main.obj: 错误 LNK2019: 函数 _main 中引用的未解析外部符号“public: void __thiscall StackLS::push(int const &)”(?push@StackLS@@QAEXABH@Z)
1>E:\C++ language 2\Well-Formed Expression Checker Solution\Debug\Well-Formed Expression Checker Project.exe : 致命错误 LNK1120: 2 unresolved externals
感谢您的帮助。
【问题讨论】:
-
从编译器错误消息中,我猜 1)
n是未引用(未使用)的局部变量,2)N是未引用的局部变量,3)answer在初始化之前使用。对于初学者,我建议删除未使用的本地变量并初始化answer。 -
这些是警告;错误来自链接器。看起来您没有正确链接 StackLS 库。
-
Lea - 请把你的 makefile 也粘贴到这里。
-
“Makefile”是使用“真实”编译器构建程序的指令。 Visual C++ 不使用它们。
标签: c++