#### Archived

This topic is now archived and is closed to further replies.

# Ugly callbacks and function pointers

This topic is 5647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is a pure design issue, I have this thing that my code should _look_ nice and don't just work nice (which it does as it is but..) First I have a base-class with two virtual callback functions which is called whenever the class needs bytes from file(or whatever the data comes from) and when the buffer is full and it needs to output data..

class Deflate
{
private:
// Lot's of private things

protected:
virtual void Get( void *data, long size ) = 0;
virtual void Put( void *data, long size ) = 0;
public:
// Some public stuff

}

Then I have the class that actually needs to decompress data as a sub-class..

class Png : public Deflate
{
private:
typedef void (cPngImage::*ZFunc)( void *, long );
ZFunc			_GetFunction;
ZFunc			_PutFunction;

void Get( void *data, long size );
void Put( void *data, long size );

public:
void Free( void );
}


however, since there is multiple deflate datastreams in a png file and I must treat those different I use function pointers to choose between different Get and Put functions..but it doesn't _look_ very nice to have those function pointers =p, is it any faster/cleaner way to do it?
/* Everything IMHO */ -Luctus [edited by - Luctus on December 5, 2002 8:26:45 AM]

##### Share on other sites
Hi there ..

so you have multiple Png classes running ? (strange)

if you like to use multiple "whatevers" in your class and you dont know how much "whatevers" there are at compiletime just use a linked list of your "whatevers" inside your class and create as much "whatevers" as needed so every "whatever" have its own set of functions ..

if you need those classes outside just use a (baseclass)pointer and get through the whole linked list.

regards

• 19
• 10
• 19
• 14
• 19