Polygon Question. Deleting a polygon in FLTK

I basically took code from the textbook and modified it to give me n-sided polygon.
However, when i loop. I need to delete the previous polygon so that the new polygon can be drawn. I tried calling delete. But I get an error saying expected pointers. Once the polygon is drawn. and I click next, and enter the new number. The program crashes. Is there a way to delete the polygon so that the next polygon can be drawn?

Line 81 Is where I would most likely delete.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#include "Simple_window.h"  // get access to our window library
#include "Graph.h"          // get access to our graphics library facilities
#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 numbers of angles.

		if(n%2 != 0){
		for(int i = 0 ; i < n ; i++){
			if(i==0){
				while(degree!=270){
					degree++;
				}
			}
                //Logic for angles.
		  }
		}else{

                 //Logic for programming 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!

	}



}
Last edited on
How did you try to delete the old polygon?
Did you call win.detach ?
Some helped me already. Yes I tried win.detach. but that seem to only disconnect the lines. The points were still there.

All I really had to do was declare Graph_lib::Polygon poly ;
inside the loop. I feel stupid.
Thanks itzjt90, this was really helpful
Do you go to ccny ?
Topic archived. No new replies allowed.