gpt4 book ai didi

c++ - Stroustrup 的 PPP 书中的多边形问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:46:52 25 4
gpt4 key购买 nike

我阅读了 Stroustrup 的书 Programming Principles and Practice using C++。在第 12 章和第 441 页中有这段代码:

//
// This is example code from Chapter 12.3 "A first example" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//

#include "Simple_window.h" // get access to our window library
#include "Graph.h" // get access to our graphics library facilities

//------------------------------------------------------------------------------

int main()
{
using namespace Graph_lib; // our graphics facilities are in Graph_lib

Point tl(100,100); // to become top left corner of window

Simple_window win(tl,600,400,"Canvas"); // make a simple window

Polygon poly; // make a shape (a polygon)

poly.add(Point(300,200)); // add a point
poly.add(Point(350,100)); // add another point
poly.add(Point(400,200)); // add a third point

poly.set_color(Color::red); // adjust properties of poly

win.attach (poly); // connect poly to the window

win.wait_for_button(); // give control to the display engine
}

//------------------------------------------------------------------------------

当我运行代码时,我得到 13 个错误,其中一定是关于 Polygon 标识符的。例如第一个错误是:错误 C2872:“多边形”:不明确的符号

请问为什么我的编译器不知道 Polygon

最佳答案

如果符号不明确,则尝试使用其限定名称:

Graph_lib::Polygon poly;

关于c++ - Stroustrup 的 PPP 书中的多边形问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20973419/

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