Hi, let me preface by saying that I am a C programmer who is working on his first C++ project.
I am having a few issues which I cannot resolve. I may not be tackling my problem correctly so I am open to suggestions on other ways to do this as well as how to fix it.
My problem is that I am trying to use the queue template to store pointers to objects. The object is called Instruction and here is the code for my class that contains the queue
Why I need to use pointers to Instructions is that I need to have multiple Queues that point to the same instructions. If I have two Queue objects the contain the same Instruction, they both need to be able to modify the same object and not a copy.Code://* Declaration class Queue { public: Queue(uint sz); ~Queue(); virtual void push(Instruction *instr); virtual Instruction *pop(); virtual bool empty() const; virtual uint size() const; virtual uint count() const; virtual Instruction *front() const; private: queue<Instruction*> data; uint size_v; uint count_v; uint front_v; uint back_v; }; //* Definition Queue::Queue(uint sz) : size_v(sz), count_v(0), front_v(0), back_v(0) { } void Queue::push(Instruction *instr) { if (count_v != size_v) { data.push(instr); ++count_v; } return; } Instruction *Queue::pop() { if (count_v != 0) { --count_v; return data.pop(); } else { return NULL; } } inline bool Queue::empty() const { return (count_v == 0); } inline uint Queue::size() const { return size_v; } inline uint Queue::count() const { return count_v; } inline Instruction *Queue::front() const { return data.front(); } Queue::~Queue() { if (count_v) { std::cout << "~Queue: " << count_v << " items remaining" << std::endl; while (count_v-- > 0) { delete data.pop; } } }
EDIT: Here is the output when compilingCode:error: ISO C++ forbids declaration of ‘queue’ with no type



LinkBack URL
About LinkBacks


