C
Chameleon
------------------------------------------------------------------------
class SizeBreaker1 : public InputStream
{
public:
void attach(InputStream &stream) { strm = &stream; }
virtual int read(void *base, int size);
private:
InputStream *strm;
};
class SizeBreaker2 : public OutputStream
{
public:
void attach(OutputStream &stream) { strm = &stream; }
virtual int write(const void *base, int size, bool flush = false);
private:
OutputStream *strm;
};
------------------------------------------------------------------------
I am not ...guru on templates, so I have this question:
Can I merge 2 classes above in a templated class?
Something like that:
------------------------------------------------------------------------
template<class T>
class SizeBreaker<T> : public T
{
public:
void attach(T &stream) { strm = &stream; }
// You must help here!
//virtual int read(void *base, int size);
//virtual int write(const void *base, int size, bool flush = false);
private:
T *strm;
};
class SizeBreaker1 : public InputStream
{
public:
void attach(InputStream &stream) { strm = &stream; }
virtual int read(void *base, int size);
private:
InputStream *strm;
};
class SizeBreaker2 : public OutputStream
{
public:
void attach(OutputStream &stream) { strm = &stream; }
virtual int write(const void *base, int size, bool flush = false);
private:
OutputStream *strm;
};
------------------------------------------------------------------------
I am not ...guru on templates, so I have this question:
Can I merge 2 classes above in a templated class?
Something like that:
------------------------------------------------------------------------
template<class T>
class SizeBreaker<T> : public T
{
public:
void attach(T &stream) { strm = &stream; }
// You must help here!
//virtual int read(void *base, int size);
//virtual int write(const void *base, int size, bool flush = false);
private:
T *strm;
};