Problem with array of function pointers

This is a discussion on Problem with array of function pointers within the C++ Programming forums, part of the General Programming Boards category; 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) : ...

  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 06: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, 09:28 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 10:48 AM

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