I am trying to write the class that will take in objs from another class and put it into a circular array without using the STL. O I wrote the class and in Main I delcared an obj of the queue called (myQueue myQ) so this is the obj but how do I make it an array?

thanks for any help.

Recommended Answers

All 2 Replies

To make a class act like an array you can overload the [] operator to simulate the same kind of indexing:

class myQueue {
public:
  myQueue(); 
  myQueue(const myQueue & CCqueue);
  myQueue& operator =(const myQueue& rhs); 
  ~myQueue();

  void enqueue(const myQueue& Contributor);
  void dequeue(); 
  bool IsEmpty();
  bool IsFull();

  int& operator[](int i)
  {
    return GetAt(i);
  }

  const int& operator[](int i) const
  {
    return GetAt(i);
  }

private:
  int& GetAt(int i)
  {
    // TODO: Get the value at i modulo size
  }

  int array[7];
  int front;//this is front
  int rear;//this is rear
  int index;
  int size;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.