Getting around a compiler error

This is a discussion on Getting around a compiler error within the C++ Programming forums, part of the General Programming Boards category; I really need to print what the address of a certain member function is, but the compiler is complaining, saying ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    54

    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,273
    The problem is in your imagination. Do what the compiler suggested.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    54
    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 12:18 PM.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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!
    CornedBee

    "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, 02:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 09: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, 07:39 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21