Thread: Problem with array of function pointers

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    167

    Problem with array of function pointers

    Borland c++ compiles the following code but visual c++ 7.1 and above complains with

    d:\Documents and Settings\Administrator\My Documents\Visual Studio\Projects\PEView\PEView\PEView.cpp(266) : error C2440: 'initializing' : cannot convert from 'int (__thiscall PEInfo::* )(void) const' to 'int (__thiscall PEInfo::* )(void)'


    . I don't understand arrays of function pointers too well or c++ for that matter so I can't figure out what might be the problem. Any help would be appreciated.

    Code:
     
      int (PEInfo::*headerFunctionList[])(void) =
      {
        &PEInfo::GetSignature, &PEInfo::GetMachine,
        &PEInfo::GetNumberOfSections, &PEInfo::GetTimeDateStamp,
        &PEInfo::GetSymbolsPointer,&PEInfo::GetNumberOfSymbols,
        &PEInfo::GetSizeOfOptionalHeader,&PEInfo::GetCharacteristics,
        &PEInfo::GetMagic,&PEInfo::GetLinkerVersion,&PEInfo::GetSizeOfCode,
        &PEInfo::GetSizeOfInitializedData, &PEInfo::GetSizeOfUninitializedData ,
        &PEInfo::GetAddressOfEntryPoint, &PEInfo::GetBaseOfCode,
        &PEInfo::GetBaseOfData, &PEInfo::GetImageBase,
        &PEInfo::GetSectionAlignment, &PEInfo::GetFileAlignment,
        &PEInfo::GetOperatingSystemVersion, &PEInfo::GetImageVersion,
        &PEInfo::GetSubsystemVersion,&PEInfo::GetWin32VersionValue ,
        &PEInfo::GetSizeOfImage,&PEInfo::GetSizeOfHeaders,
        &PEInfo::GetCheckSum, &PEInfo::GetSubsystem ,
        &PEInfo::GetDLLCharacteristics, &PEInfo::GetSizeOfStackReserve ,
        &PEInfo::GetSizeOfStackCommit, &PEInfo::GetSizeOfHeapReserve ,
        &PEInfo::GetSizeOfHeapCommit, &PEInfo::GetLoaderFlags ,
        &PEInfo::GetNumberOfRVAsAndSizes
     };
    Last edited by silk.odyssey; 08-24-2004 at 05:49 PM.
    silk.odyssey

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    I looked at the error more closely and I think that I've found the source of the problem

    I replaced

    int (PEInfo::*headerFunctionList[])(void) =
    with
    int (PEInfo::*headerFunctionList[])(void) const =

    and it works.
    silk.odyssey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM