counting the number of times that a command has been issued/or a function has been used

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
Last edited on
you can send a int by reference to the function as well and update it within the function
I dont understand exactly what you mean!
this is my class:
class CommansClass
string **array;
int size, i , j , row, col , Mrow , Mcol;
string ch;
void intialization(string);
void ArrayOut();
void rectangle(int,int,int,int, string);
void circle(int , int , double , string);
void LeftTriangle(int, int, int,int, string);
void RightTriangle(int, int, int,int,string);
void Triangle2(int, int , int ,int ,int , string);
void setPen(const string );
string getPen();

and this is the definition of the canvas within the class:
CommansClass::CommansClass(int col, int row)
array= new string *[row];
for(i=0; i<row;i++)
array[i]= new string[col];

So what should I do according to your suggestion?
static int counter;
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.
Topic archived. No new replies allowed.