释放并重新分配内存。在FLTK中重置多边形

时间:2017-05-23 01:00:34

标签: memory polygon fltk

#include "Simple_window.h"   
#include "Graph.h"          
#include <math.h>
#include <iostream>
#include <limits>
using namespace std;

int main(){

    Simple_window win(Point(100,100),600,400,"Marks");



    Graph_lib::Polygon poly;
    bool over = true;
    int n = 0;

    while(over){
            Marks pp("x");
            pp.add(Point(300,200));

            cout<<"Enter number of sides (3 or more): ";
            while(!(cin>>n)){
                cin.clear();
                  cin.ignore(numeric_limits<streamsize>::max(), '\n');
                  cout<<"Enter number of sides (3 or more): ";

            }
            if(n<3){
                break;

            }

    //Finding the angle and number of sides...

        if(n%2 != 0){
        //logic for polygon...



          }
        }else{

        //logic for polygon...
            }


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

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

    win.attach(pp);

    win.wait_for_button();       // Display!


    }



}

这个程序是什么使它成为n边多边形。设置多边形后。我希望重置它。我输入多边形中的边数量后。我点击&#34; next&#34;它会再问我多少个多边形并重复这个过程。有人告诉我打电话给删除。但是,我不确定如何输入。如删除poly.points?还是删除多边形?我尝试了一些,但我一直都有错误。

我的第二个问题是在第38行。最初我有这样的问题。如果我输入的数字小于3,程序将结束。但该计划不会结束。所以我不得不使用break;

if(n<3){
    over=false;
    cout<<"why wont this end ?"<<endl;

}

boolean over设置为true。而真正的循环。如果n < 3结束是假的。从而结束了该计划?它不会结束。

1 个答案:

答案 0 :(得分:0)

如果您在第一个while循环中粘贴声明,则无需重置poly。

while(over){
    Graph_lib::Polygon poly;
    ...
    win.wait_for_button();
}

Re:为什么你的节目不会结束。休息是足够好但如果你不喜欢使用休息

  • 使用继续
  • 将其余的循环体放入else子句

编辑:Re:更改标题:我不知道Simpe_Window界面:它不是FLTK的一部分 - 它是Stroustrup的创建。如果它是从FL_Window派生的,请使用label(新标题)。

相关问题