P
Pallav singh
Hi
i am getting error while executing the following code
#include <iostream>
using namespace std;
class Gaint
{
public :
Gaint(){ id = next++; }
void func1(){ cout<<" Inside Function 1 "<<endl; }
void func2(){ cout<<" Inside Function 2 "<<endl; }
void func3(){ cout<<" Inside Function 3 "<<endl; }
private :
int id;
static int next;
};
int Gaint::next = 0;
class Command
{
public :
typedef void (Gaint:: *Action)();
Command( Gaint * _object , Action _method )
{ object = _object;
method = _method;
}
void execute()
{ (object->*method)(); }
private :
Gaint * object;
Action * method;
};
template<typename T>
class queue
{
public :
enum { SIZE = 8 };
T * array[SIZE];
int add , remove;
queue(){ add = remove = 0;}
void enqueue(T * c)
{
array[add] = c;
add = (add + 1) % SIZE;
}
T * dequeue()
{
int tmp = remove;
remove =(remove + 1) % SIZE;
return array[tmp];
}
};
int main()
{
queue<Command > que;
Command * input[] = {
new Command(new Gaint(), &Gaint::func1),
new Command(new Gaint(), &Gaint::func2),
new Command(new Gaint(), &Gaint::func3),
new Command(new Gaint(), &Gaint::func1),
new Command(new Gaint(), &Gaint::func2),
new Command(new Gaint(), &Gaint::func3)
};
for( int i =0 ; i< 6 ; i++)
que.enqueue(input);
for( int i =0 ; i< 6 ; i++)
que.dequeue()->execute();
return 0;
}
i am getting error while executing the following code
#include <iostream>
using namespace std;
class Gaint
{
public :
Gaint(){ id = next++; }
void func1(){ cout<<" Inside Function 1 "<<endl; }
void func2(){ cout<<" Inside Function 2 "<<endl; }
void func3(){ cout<<" Inside Function 3 "<<endl; }
private :
int id;
static int next;
};
int Gaint::next = 0;
class Command
{
public :
typedef void (Gaint:: *Action)();
Command( Gaint * _object , Action _method )
{ object = _object;
method = _method;
}
void execute()
{ (object->*method)(); }
private :
Gaint * object;
Action * method;
};
template<typename T>
class queue
{
public :
enum { SIZE = 8 };
T * array[SIZE];
int add , remove;
queue(){ add = remove = 0;}
void enqueue(T * c)
{
array[add] = c;
add = (add + 1) % SIZE;
}
T * dequeue()
{
int tmp = remove;
remove =(remove + 1) % SIZE;
return array[tmp];
}
};
int main()
{
queue<Command > que;
Command * input[] = {
new Command(new Gaint(), &Gaint::func1),
new Command(new Gaint(), &Gaint::func2),
new Command(new Gaint(), &Gaint::func3),
new Command(new Gaint(), &Gaint::func1),
new Command(new Gaint(), &Gaint::func2),
new Command(new Gaint(), &Gaint::func3)
};
for( int i =0 ; i< 6 ; i++)
que.enqueue(input);
for( int i =0 ; i< 6 ; i++)
que.dequeue()->execute();
return 0;
}