Stroustrup 的 PPP 书中的多边形问题 [英] Trouble with Polygon in Stroustrup's PPP book

查看:24
本文介绍了Stroustrup 的 PPP 书中的多边形问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了Stroustrup 的书《使用C++ 的编程原理和实践》.在第 12 章和第 441 页中有以下代码:

I read Programming Principles and Practice using C++, Stroustrup's book. In chapter 12 and in page 441 there is this code:

//
// 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:多边形":不明确的符号

When I ran the code I get 13 errors which must of them are about the Polygon identifier. For example first error is: Error C2872: 'Polygon' : ambiguous symbol

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

Why my compiler doesn't know that Polygon please?

推荐答案

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

If the symbol is ambiguous then try to use its qualified name:

Graph_lib::Polygon poly;

这篇关于Stroustrup 的 PPP 书中的多边形问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆