954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with circular arrays without STL

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.

Attachments myQueue.cpp (2KB) myQueue.h (0.48KB) lab.cpp (1.39KB)
phillipeharris
Newbie Poster
20 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

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;
};
Radical Edward
Posting Pro
545 posts since May 2008
Reputation Points: 361
Solved Threads: 97
 

Thanks man

phillipeharris
Newbie Poster
20 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You