I have written some codes for a program that does Ascii-art.
I wrote it with a class and some class member functions.
I have the command " canvas x y" that whenever this command be issued the program create a new canvas with the specified size. and after getting a pen like "pen j"
and the command "rectangle l t r b" (l and r identify the horizontal range and t and b identify vertical range) it uses the pen to draw a rectangle.
the first time it creates a new empty canvas with command "canvas x y", but second time it sholud resize the canvas and if any new pen has not been issued it should resize the canvas and copy the content of previous canvas in the new one.
I think i know how to resize it and copy the characters from previous canvas in new one, but I dont know how can it distinguesh that the command " canvas x y" is the second time that the canvas command has been issued or is the first time.
How can I distinguish that the current command is the nth time that is has been issued since the time program started
thank you in advance for your help
and then in your constructor for the class just do counter++ so whenever you declare a new object it adds one to the static variable(read more about static to find out why/how) and the variable will hold the number of the objects
NOTE: in the destructor you need to remember to do counter-- to say you removed one of the objects.