noobie: use virtual functions?

Started by
4 comments, last by McLin 21 years, 11 months ago
im new to virtual functions(but i know how they work), wondering if anyone can help me with this: Im trying to write a direct draw display class which contains a bunch of function pointers. Upon initialization to a particular res and bpp, it fills in the function pointers with (member)drawing functions of the appropriate bpp. I cant get this to compile. i get type mismatches when i try to set the function pointers. seeing as virtul functions are all about function poitners, is there a better way to do this using inherited classes? Id really appreciate any advice --MCLIN--
Advertisement
I''m probably not the best to be answering this post but i''ll have a go...


Let me see if i''ve got this right, you have 1 function pointer per class that points to the member function that will draw at the orrect bit depth and res? In that case, why do you need/want to use virtual functions? Since you don''t seem to be accessing the class through a base pointer there seems little need for it.

The mismatch is probably just needs a cast to tip it in the right direction, post the code thats throwing up the error.

dis
Pointers to member functions.

[ C++ FAQ Lite | ACCU | Boost | Python | Agile Manifesto! ]
thanks for the replies ppl.

So how can i get the member function pointers to member functions going?

here''s my code:

class CDisplay
{
public:
void (*plotpixel)(int x, int y, int red, int green, int blue);
void plotpixel16(int x, int y, int red, int green, int blue);
};

later in the init member function of CDisplay,

plotpixel = plotpixel16; //<-- error

the error it gives me is
= cant convert from (__thiscall CDisplay::*)(int,int,int,int,int)
to (__cdecl *)(int,int,int,int,int)

__cdecl? got me.
that article that article that sabreman posted is about non-member function pointers to member functions. im confused
Woo!! did a little messing and found another error that i had made. it works if i use (CDisplay::* plotpixel)(int...) instead.

Woo!! thanks you two
quote:Original post by McLin
that article that article that sabreman posted is about non-member function pointers to member functions. im confused

No it''s not. You can''t have a non-member function pointer point to a member function. There is no conversion. Read it again, and pay particular attention to this.

This topic is closed to new replies.

Advertisement