-
Stack of istreams
GAH! this is giving me gray hairs. how the jeef do i write a class for a stack of type istream? i don't need a template, since this is only to be used for istream.
here's the basic stuff i have written so far:
Code:
#ifndef _ISSTACK_H
#define _ISSTACK_H
#include <iostream.h>
#include <fstream.h>
class ISStack{
private:
int count_, size_;
istream **stack_;
public:
ISStack();
ISStack(const ISStack &);
~ISStack();
void push(istream *);
istream* pop();
void increaseSize();
};
#endif;
count_ = the amount of stuff in the array
size_ = maximum amount of stuff in the array
istream ** stack_ = the array of pointers to istreams
i have a copy constructor so i can pass this array of pointers by value, if necessary. i have a destructor because it's a dynamic data structure that needs to be deallocated when i'm finished with it. as this stands, ISStack(), ISStack(const ISStack &), ~ISStack, void push(istream *), and void increaseSize() work. it's the pop() that i'm having a trouble with.
is there anyone on this board who has written a class for istream stacks, or knows where i can get a nice and simple one? hell, even a plain-old stack class is fine, as long as it is VERY EASILY modifiable to support istreams and can compile using g++ 2.95.
thanks in advance
edk
-
Hmm, is there any particular reason you can't use the standard C++ stack template? I'm pretty sure it would save you a lot of trouble. Just include the 'stack' header. Check a reference for usage, or just read through the header file itself. It's pretty easy to use. (g++ 2.95.x has this header, btw.)
-
I'd recommend using STL containers like vector, deque, map, and so on... They're very effective and modificable.
Ex:
vector<WhatEverClass*> V1;
V1.push_back(&object);
...and so on... see your help files.