【发布时间】:2015-02-09 07:00:36
【问题描述】:
以下代码是应用程序的一小部分。对于那个应用程序,我需要使用 in_box.get_string()。 in_box 的声明和定义在GUI.h 和GUI.cpp 文件的this 地址中。
对于整数,它工作正常。也就是说,如果我使用 in_box.get_int(),它会获取输入到 in_box 的数字并将该数字作为 integer 返回。但问题是,正如预期的那样,它不适用于strings。当使用字符串时,我得到错误!
例如,在下面的代码中,我使用了string s。
#include <GUI.h>
#include <iostream>
using namespace Graph_lib;
class Calculator : public Window {
public:
Calculator(Point, int, int, const string&);
private:
//Widgets
Button show_button;
In_box enter_box;
void show() { getstr(); cout <<s; }
void getstr() {
s = enter_box.get_string();
}
static void cb_show(Address, Address pw) { reference_to<Calculator>(pw).show(); }
string s;
};
//---------------------------------------------------------------------
Calculator::Calculator(Point xy, int w, int h, const string& title):
Window(xy, w, h, title),
show_button(Point(x_max()-110, 440), 90, 35, "Show", cb_show),
enter_box(Point(x_max()-400, 158), 245, 40, "Enter"){
attach(enter_box);
attach(show_button);
}
int main()
{
Calculator cal(Point(100,100), 600, 500, "Calculator");
return gui_main();
}
有 8 个警告和两个错误。错误如下:
错误 9 错误 LNK2019: 无法解析的外部符号 "public: class std::basic_string,class std::allocator > __thiscall Graph_lib::In_box::get_string(void)" (?get_string@In_box@Graph_lib@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 在函数“private: void __thiscall”中引用 计算器::getstr(void)" (?getstr@Calculator@@AAEXXZ) C:\Users\ME\documents\visual studio 2012\Projects\test_3\test_3\test_3.obj 错误 10 错误 LNK1120:1 未解决的外部 C:\Users\ME\documents\visual studio 2012\Projects\test_3\Debug\test_3.exe
错误说,这是一个链接器问题,但我的链接器输入的文件列表如下,到目前为止它(几乎)工作正常。
fltkd.lib
wsock32.lib
comctl32.lib
fltkjpegd.lib
fltkimagesd.lib
我的编译器是 MS VS 2012。机器是 Win 7。
请问有人知道怎么解决吗?
【问题讨论】:
标签: c++ visual-c++ visual-studio-2012 fltk