无法将编程原理中的示例与使用c++的实践联系起来

can not link examples from programming principles and practice using c++

本文关键字:c++ 起来 联系 编程      更新时间:2023-10-16

我正在尝试编译并链接下面的源代码。当我在Visual Studio 2012中启动构建序列时,我会收到以下错误(还有一些与Graph_lib相关的错误)。我不明白为什么链接失败——所有的代码都可用。我已经验证了符号定义和声明。

Error   11  error LNK1120: 10 unresolved externals  C:Microsoft_PressC++Debugfirst_guiDebugfirst_gui.exe  first_gui
Error   4   error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Shape::draw_lines(void)const " (?draw_lines@Shape@Graph_lib@@MBEXXZ)   C:Microsoft_PressC++Debugfirst_guifirst_guisource.obj first_gui
Error   1   error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Window::draw(void)" (?draw@Window@Graph_lib@@MAEXXZ)   C:Microsoft_PressC++Debugfirst_guifirst_guisource.obj first_gui
Error   6   error LNK2001: unresolved external symbol "public: virtual void __thiscall 

#include "std_lib_facilities.h"
#include "Simple_window.h"
#include "Graph.h"
int main()
{
    using namespace Graph_lib;
    Point tl(100,100);
    Simple_window win(tl,600,400,"canvas");
    Polygon poly;
    poly.add(Point(300,200));
    poly.add(Point(350,100));
    poly.add(Point(400,200));
    poly.set_color(Color::red);
    win.attach(poly);
    win.wait_for_button();
}
1>------ Build started: Project: first_gui, Configuration: Debug Win32 ------
1>source.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Window::draw(void)" (?draw@Window@Graph_lib@@MAEXXZ)
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Shape::move(int,int)" (?move@Shape@Graph_lib@@UAEXHH@Z)
1>source.obj : error LNK2019: unresolved external symbol "protected: __thiscall Graph_lib::Shape::Shape(void)" (??0Shape@Graph_lib@@IAE@XZ) referenced in function "public: __thiscall Graph_lib::Open_polyline::Open_polyline(void)" (??0Open_polyline@Graph_lib@@QAE@XZ)
1>source.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Shape::draw_lines(void)const " (?draw_lines@Shape@Graph_lib@@MBEXXZ)
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Open_polyline::draw_lines(void)const " (?draw_lines@Open_polyline@Graph_lib@@UBEXXZ)
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Closed_polyline::draw_lines(void)const " (?draw_lines@Closed_polyline@Graph_lib@@UBEXXZ)
1>source.obj : error LNK2019: unresolved external symbol "public: void __thiscall Graph_lib::Polygon::add(struct Point)" (?add@Polygon@Graph_lib@@QAEXUPoint@@@Z) referenced in function _main
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Polygon::draw_lines(void)const " (?draw_lines@Polygon@Graph_lib@@UBEXXZ)
1>source.obj : error LNK2019: unresolved external symbol "public: __thiscall Simple_window::Simple_window(struct Point,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Simple_window@@QAE@UPoint@@HHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
1>source.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Simple_window::wait_for_button(void)" (?wait_for_button@Simple_window@@QAE_NXZ) referenced in function _main
1>C:Microsoft_PressC++Debugfirst_guiDebugfirst_gui.exe : fatal error LNK1120: 10 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

@dlf发布了一个MSDN链接,建议将.cpp文件添加到项目中。我按照指示进行了操作,现在我可以成功地构建和链接了。

相关文章: