gpt4 book ai didi

c++ - 尝试使用 C++ 图形,我已经包含了头文件,甚至出现错误?

转载 作者:行者123 更新时间:2023-11-30 04:07:27 25 4
gpt4 key购买 nike

我正在努力学习 C++。目前,我正在关注一本名为“C++ 中的面向对象编程”第四版(Robert Lafore 着)的书。这本书第 225 页有一个关于对象和类的例子。我分享了下面的示例,并设法下载了包含的文件并将它们解压缩到项目文件夹中。所以现在我的项目文件包含一个名为“msoftcon.c”和“msoftcon.h”的文件。当我尝试编译该项目时,出现错误“对‘init_graphics()’的 undefined reference ”,而此函数在 msoftcon.c 中非常重要。示例如下:

 #include <iostream>
#include "msoftcon.h"
using namespace std;

class circle
{
protected:

int xCo, Yco; //coordinates of center
int radius;
color fillcolor; //color
fstyle fillstyle; //fill pattern

public:

void set(int x, int y, int r, color fc, fstyle fs)
{
xCo = x;
Yco = y;
radius = r;
fillcolor = fc;
fillstyle = fs;
}
void draw()
{
set_color(fillcolor); //set color
set_fill_style(fillstyle); //set till
draw_circle(xCo, Yco, radius); //draw solid circle
}

};

int main()
{
init_graphics();

return 0;
}

最佳答案

很可能您未能将 msoftcon.c 和关联的 .h 添加到您的项目中。仅仅直接在你的项目中解压它是不够的。它需要实际添加到项目中,之后将被编译并与其他文件链接,希望能消除您看到的错误。

具体如何完成取决于您的设置(IDE 等)。

关于c++ - 尝试使用 C++ 图形,我已经包含了头文件,甚至出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22504354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com