Thread: Getting around a compiler error

  1. #1
    Registered User
    Join Date
    Feb 2006

    Getting around a compiler error

    I really need to print what the address of a certain member function is, but the compiler is complaining, saying
    "error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function. "
    It suggests saying &ClassName::MemberName, but the problem is that this function is pure virtual, so that would probably just print 00000000 or perhaps the address of some runtime-error generating function.
    How can I get around this error to allow me to get what this function is currently set to in the vtable?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    The problem is in your imagination. Do what the compiler suggested.
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

  3. #3
    Registered User
    Join Date
    Feb 2006
    Logfile now says: Called function: 00000065 (that's what it claims, but the call works fine, and calls a function somewhere near 0x7000000 i think)
    The library with the function is based somewhere around 0x70000000, so 00000065 is clearly just something that generates an exception.

    I only have the interface, not the source for the actual implementation.
    Last edited by Doodle77; 07-15-2008 at 11:18 AM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Function pointers are interesting beasts. Suffice to say, when you take the "address" of a virtual function, what you really get is something compiler-specific that, when called with an object supplied, resolves the virtual call. Like an offset into the vtable. (Though unless your interface truly has over a hundred virtual functions, the 0x65 you get out is not a word offset - and since it's not aligned, it's probably not a byte offset either.)

    If you want the actual address ... there's no portable way to achieve this. There may not even be a non-portable for some systems.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

Tags for this Thread