Re: How to declare pointers to virtual base class methods ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Reconsider your design. Apart from compiler being unable to cast member
pointers, your design invokes undefined behavior and even if you make it
compile it will crash and burn one day.
You'are trying to establish callbacks to the derived class member functions.
That should immediately be a red flag for you. My experience tells me that
when people start employing callbacks, that usually indicates a faulty
design, or deficiencies of the language (e.g. lack of natural event
support), or crossing language boundaries (e.g. c/c++)
Probably in your case you need to design a clear base class interface with
virtual functions that will be overridden as necessary in derived classes.

Gene

"Ingo" <Ingo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2D76B748-E0C6-44E9-A144-C428734C471C@xxxxxxxxxxxxxxxx
> Hi All!
>
> I have a problem in using pointers to methods of a base class.
> I define two classes A and B where B inherits from A. Class A has a method
> that takes a pointer to a method of A as an argument. Even if I apply this
to
> a class B derived from A, everything works fine (however an explicit type
> casting to the method pointer type of class A is necessary).
>
> Now here is my problem:
> The class structure makes usage of multiple inheritance and virtual
classes.
> If we now declare the inherited class A as virtual, the compiler does not
> accept the method pointer types anymore and throws an error.


.



Relevant Pages

  • Re: How to convert Infix notation to postfix notation
    ... and make all strings const save where the intent ... function whose contract is to change the string. ... the compiler "just" prevents the string ... try to do using the pointer you get. ...
    (comp.lang.c)
  • Re: Mex Overflow Error Using Free Borland Compiler
    ... >>>would clean up a lot of code by eliminating the pointer dereferences. ... >>>guaranteed by the standard and should not be relied on. ... >>>You can try the GNU C compiler available on mingw or cygwin. ... >>>the Constraints are then both operands shall have arithmetic type. ...
    (comp.soft-sys.matlab)
  • Re: Anybody here endure C/Cpp? (.h to .inc conversion)
    ... Pascal or Stdcall convention... ... "PFNGLPOINTPARAMETERFEXTPROC" to be a type that's a pointer to a function ... DWORD, using a 32-bit compiler, with an address in it...adding the ... this is working on the premise that OpenGL does it like most others ...
    (alt.lang.asm)
  • Re: Why the compiler applies sign extension to unsigned data?
    ... I want the value of p to be made unsigned *before* the cast. ... want the cast to generate a sign extension. ... ULONG_PTR is ULONG and casting the pointer to ULONG_PTR first is the ... on the compiler and on the knowledge of the size of the ptr variable, ...
    (microsoft.public.development.device.drivers)
  • Re: OO programming - illumination? - whoopsie
    ... > represented by a host of loosely related arrays. ... > compiler and the memory allocators. ... A pointer is usually a word. ... organs can be further modeled to include cells and so on and so forth. ...
    (comp.lang.java.programmer)