Function Pointers and Error: Could not find a match

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Parent

    Function Pointers and Error: Could not find a match

    I have perused through the groups and a couple C++ manuals and haven't
    been able to figure this one out. Maybe I'm staring at it too much.
    Here's the setup, I have 2 files. One is a library and one is the
    program source:

    MyLibrary.C
    -----------

    int InstallSigHandl er( void (*sigHandler) (int) )
    {
    // ....
    return ...
    }


    MyMain.C
    --------

    #include MyLibrary.h
    void *MySigHandler(i nt);

    main()
    {
    InstallSigHandl er(MySigHandler ); <== Error Line
    }
    void *MySigHandler(i nt x)
    {
    // ...
    }

    Error: Could not find a match for InstallSigHandl er( void*(int)).
    --------------------

    The library, MyLibrary, compiles without warnings or errors and is
    successfully included when I compile MyMain.C. However, I receive the
    error above when compiling MyMain.C.

    I feel like there should be parentheses around the void* in the error
    message. Not sure. But if anyone out there could lend some advice,
    thanks.

    Chris
  • MiniDisc_2k2

    #2
    Re: Function Pointers and Error: Could not find a match


    "Christophe r Parent" <djkibblez@yaho o.com> wrote in message
    news:3534fe50.0 306250654.10d33 d15@posting.goo gle.com...[color=blue]
    > I have perused through the groups and a couple C++ manuals and haven't
    > been able to figure this one out. Maybe I'm staring at it too much.
    > Here's the setup, I have 2 files. One is a library and one is the
    > program source:
    >
    > MyLibrary.C
    > -----------
    >
    > int InstallSigHandl er( void (*sigHandler) (int) )
    > {
    > // ....
    > return ...
    > }
    >
    >
    > MyMain.C
    > --------
    >
    > #include MyLibrary.h
    > void *MySigHandler(i nt);[/color]

    Looks to me like this returns a pointer to void, not what you intended, the
    address of a function which returns void? Try this

    void (*MySigHandler) (int)
    [color=blue]
    >
    > main()
    > {
    > InstallSigHandl er(MySigHandler ); <== Error Line[/color]

    or alternatively change it here:
    InstallSigHandl er(&MySigHandle r);
    and get rid of the * in the function declaration above.
    [color=blue]
    > }
    > void *MySigHandler(i nt x)[/color]

    Change this to match the function declaration.
    [color=blue]
    > {
    > // ...
    > }
    >
    > Error: Could not find a match for InstallSigHandl er( void*(int)).[/color]
    This indicates that it's looking for a function which will accept a function
    to return a void*. Not what you intended.
    ----------[color=blue]
    >
    > The library, MyLibrary, compiles without warnings or errors and is
    > successfully included when I compile MyMain.C. However, I receive the
    > error above when compiling MyMain.C.
    >
    > I feel like there should be parentheses around the void* in the error
    > message.[/color]

    Yup. See above.
    [color=blue]
    > Not sure.[/color]

    No seriously, you're right.
    [color=blue]
    > But if anyone out there could lend some advice,
    > thanks.[/color]

    No problem.
    [color=blue]
    >
    > Chris[/color]

    -- MiniDisc_2k2
    To reply, replace nospam.com with cox dot net


    Comment

    • Victor Bazarov

      #3
      Re: Function Pointers and Error: Could not find a match

      "Christophe r Parent" <djkibblez@yaho o.com> wrote...[color=blue]
      > I have perused through the groups and a couple C++ manuals and haven't
      > been able to figure this one out. Maybe I'm staring at it too much.
      > Here's the setup, I have 2 files. One is a library and one is the
      > program source:
      >
      > MyLibrary.C[/color]
      ^^^
      [color=blue]
      > -----------
      >
      > int InstallSigHandl er( void (*sigHandler) (int) )
      > {
      > // ....
      > return ...
      > }
      >
      >
      > MyMain.C
      > --------
      >
      > #include MyLibrary.h[/color]
      ^^^^
      Are you sure that 'InstallSigHanl der' is correctly _declared_ in
      that header? Since you didn't post it we have no way to verify
      that.
      [color=blue]
      > void *MySigHandler(i nt);
      >
      > main()[/color]

      Should be

      int main()
      [color=blue]
      > {
      > InstallSigHandl er(MySigHandler ); <== Error Line
      > }
      > void *MySigHandler(i nt x)
      > {
      > // ...
      > }
      >
      > Error: Could not find a match for InstallSigHandl er( void*(int)).
      > --------------------
      >
      > The library, MyLibrary, compiles without warnings or errors and is
      > successfully included when I compile MyMain.C. However, I receive the
      > error above when compiling MyMain.C.[/color]

      Is that error during compilation or during linking? If during
      compilation, make sure the declaration of 'InstallSigHand ler' is
      visible when 'MyMain.C' is compiled. If it's during linking,
      then, I am sorry, the library must be either built wrong or with
      different settings (like for C, not C++, linkage).
      [color=blue]
      >
      > I feel like there should be parentheses around the void* in the error
      > message.[/color]

      We can't fix that, and you have no control over that. It's what
      the compiler manufacturer made it report.
      [color=blue]
      > Not sure. But if anyone out there could lend some advice,
      > thanks.[/color]

      I think you might want to post more code (like "MyLibrary. h", for
      example), and perhaps think of posting to your compiler newsgroup,
      they know more about compiler settings and how to make your libs
      to link correctly.

      Victor


      Comment

      • Victor Bazarov

        #4
        Re: Function Pointers and Error: Could not find a match

        "Tom" <tom@yahoo.co m> wrote...[color=blue]
        > Lib:
        > int InstallSigHandl er(void (sigHandler)(in t))[/color]

        (a) This should be

        int InstallSigHandl er(void (*sigHandler)(i nt))
        [color=blue]
        > {
        > ...
        > }
        >
        > App:
        > void MySigHandler(in t);
        >
        > void main (void)
        > {
        > InstallSigHandl er(&MySigHandle r);[/color]

        (b) The '&' is unnecessary.
        [color=blue]
        > }
        >
        > void MySigHandler(in t x)
        > {
        > ...
        > }
        >
        > This should work![/color]

        With the correction (a) it will.
        [color=blue]
        >
        > Regards,
        > Tom
        >
        > "Christophe r Parent" <djkibblez@yaho o.com> wrote in message
        > news:3534fe50.0 306250654.10d33 d15@posting.goo gle.com...[color=green]
        > > I have perused through the groups and a couple C++ manuals and haven't
        > > been able to figure this one out. Maybe I'm staring at it too much.
        > > Here's the setup, I have 2 files. One is a library and one is the
        > > program source:
        > >
        > > MyLibrary.C
        > > -----------
        > >
        > > int InstallSigHandl er( void (*sigHandler) (int) )
        > > {
        > > // ....
        > > return ...
        > > }
        > >
        > >
        > > MyMain.C
        > > --------
        > >
        > > #include MyLibrary.h
        > > void *MySigHandler(i nt);
        > >
        > > main()
        > > {
        > > InstallSigHandl er(MySigHandler ); <== Error Line
        > > }
        > > void *MySigHandler(i nt x)
        > > {
        > > // ...
        > > }
        > >
        > > Error: Could not find a match for InstallSigHandl er( void*(int)).
        > > --------------------
        > >
        > > The library, MyLibrary, compiles without warnings or errors and is
        > > successfully included when I compile MyMain.C. However, I receive the
        > > error above when compiling MyMain.C.
        > >
        > > I feel like there should be parentheses around the void* in the error
        > > message. Not sure. But if anyone out there could lend some advice,
        > > thanks.
        > >
        > > Chris[/color]
        >
        >[/color]


        Comment

        • MiniDisc_2k2

          #5
          Re: Function Pointers and Error: Could not find a match


          "Victor Bazarov" <v.Abazarov@att Abi.com> wrote in message
          news:vfjh1f7dap 6k29@corp.super news.com...[color=blue]
          > "Tom" <tom@yahoo.co m> wrote...[color=green]
          > > Lib:
          > > int InstallSigHandl er(void (sigHandler)(in t))[/color]
          >
          > (a) This should be
          >
          > int InstallSigHandl er(void (*sigHandler)(i nt))[/color]

          Just what I was going to say...[color=blue]
          >[color=green]
          > > {
          > > ...
          > > }
          > >
          > > App:
          > > void MySigHandler(in t);
          > >
          > > void main (void)
          > > {
          > > InstallSigHandl er(&MySigHandle r);[/color]
          >
          > (b) The '&' is unnecessary.[/color]

          But it helps maintain readability.


          Comment

          • Alexander Terekhov

            #6
            Re: Function Pointers and Error: Could not find a match


            Victor Bazarov wrote:
            [...][color=blue][color=green]
            > > App:
            > > void MySigHandler(in t);
            > >
            > > void main (void)
            > > {
            > > InstallSigHandl er(&MySigHandle r);[/color]
            >
            > (b) The '&' is unnecessary.[/color]

            (c) http://groups.google.com/groups?selm...7C600%40web.de

            regards,
            alexander.

            Comment

            • Victor Bazarov

              #7
              Re: Function Pointers and Error: Could not find a match

              "Christophe r Parent" <djkibblez@yaho o.com> wrote...[color=blue]
              > Alright, I've made some changes, and I know longer get any compilation
              > errors,[/color]

              You don't? Your compiler must be more forgiving than mine.
              [color=blue]
              > but now I'm getting a link error. Here's what I've done:
              >
              > MyLibrary.C/h (This is the same as before)
              > -----------
              >
              > int InstallSigHandl er( void (*sigHandler) (int) )
              > {
              > ...;
              > }
              >
              > MyProgram.C
              > -----------
              >
              > #include MyLibrary.h[/color]

              #include <MyLibrary.h>
              [color=blue]
              > void MySigHandler(in t);
              >
              > main()[/color]

              int main()
              [color=blue]
              > {
              > InstallSigHandl er(MySigHandler );
              > }
              >
              > void MySigHandler(in t x)
              > {
              > // ...
              > }
              >
              > The linkage error that I'm getting is
              >
              > Undefined symbol first referenced in file
              > int InstallSigHandl er(void(*)(int) ) MyProgram.o[/color]

              Are you sure you're including all compiled files at the linking
              stage of making the program?


              Comment

              • MiniDisc_2k2

                #8
                Re: Function Pointers and Error: Could not find a match

                Ensure that the compiler is actually compiling both files (and that the
                linker is linking the two together). Perhaps you could combine them into one
                file?
                -- MiniDisc_2k2

                To reply, replace nospam.com with cox dot net


                Comment

                • Ron Natalie

                  #9
                  Re: Function Pointers and Error: Could not find a match

                  [color=blue]
                  > void MySigHandler(in t);[/color]

                  Do you want
                  extern "C" void MySigHandler(in t);
                  [color=blue]
                  >
                  > main()[/color]

                  must provide return value (int) for main.



                  Comment

                  Working...