Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Function Pointers and Error: Could not find a match

Reply
Thread Tools

Function Pointers and Error: Could not find a match

 
 
Christopher Parent
Guest
Posts: n/a
 
      06-25-2003
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 InstallSigHandler( void (*sigHandler) (int) )
{
// ....
return ...
}


MyMain.C
--------

#include MyLibrary.h
void *MySigHandler(int);

main()
{
InstallSigHandler(MySigHandler); <== Error Line
}
void *MySigHandler(int x)
{
// ...
}

Error: Could not find a match for InstallSigHandler( 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
 
Reply With Quote
 
 
 
 
MiniDisc_2k2
Guest
Posts: n/a
 
      06-25-2003

"Christopher Parent" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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 InstallSigHandler( void (*sigHandler) (int) )
> {
> // ....
> return ...
> }
>
>
> MyMain.C
> --------
>
> #include MyLibrary.h
> void *MySigHandler(int);


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)

>
> main()
> {
> InstallSigHandler(MySigHandler); <== Error Line


or alternatively change it here:
InstallSigHandler(&MySigHandler);
and get rid of the * in the function declaration above.

> }
> void *MySigHandler(int x)


Change this to match the function declaration.

> {
> // ...
> }
>
> Error: Could not find a match for InstallSigHandler( void*(int)).

This indicates that it's looking for a function which will accept a function
to return a void*. Not what you intended.
----------
>
> 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.


Yup. See above.

> Not sure.


No seriously, you're right.

> But if anyone out there could lend some advice,
> thanks.


No problem.

>
> Chris


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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-25-2003
"Christopher Parent" <(E-Mail Removed)> wrote...
> 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 InstallSigHandler( void (*sigHandler) (int) )
> {
> // ....
> return ...
> }
>
>
> MyMain.C
> --------
>
> #include MyLibrary.h

^^^^
Are you sure that 'InstallSigHanlder' is correctly _declared_ in
that header? Since you didn't post it we have no way to verify
that.

> void *MySigHandler(int);
>
> main()


Should be

int main()

> {
> InstallSigHandler(MySigHandler); <== Error Line
> }
> void *MySigHandler(int x)
> {
> // ...
> }
>
> Error: Could not find a match for InstallSigHandler( 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.


Is that error during compilation or during linking? If during
compilation, make sure the declaration of 'InstallSigHandler' 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).

>
> I feel like there should be parentheses around the void* in the error
> message.


We can't fix that, and you have no control over that. It's what
the compiler manufacturer made it report.

> Not sure. But if anyone out there could lend some advice,
> thanks.


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


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      06-25-2003
"Tom" <(E-Mail Removed)> wrote...
> Lib:
> int InstallSigHandler(void (sigHandler)(int))


(a) This should be

int InstallSigHandler(void (*sigHandler)(int))

> {
> ...
> }
>
> App:
> void MySigHandler(int);
>
> void main (void)
> {
> InstallSigHandler(&MySigHandler);


(b) The '&' is unnecessary.

> }
>
> void MySigHandler(int x)
> {
> ...
> }
>
> This should work!


With the correction (a) it will.

>
> Regards,
> Tom
>
> "Christopher Parent" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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 InstallSigHandler( void (*sigHandler) (int) )
> > {
> > // ....
> > return ...
> > }
> >
> >
> > MyMain.C
> > --------
> >
> > #include MyLibrary.h
> > void *MySigHandler(int);
> >
> > main()
> > {
> > InstallSigHandler(MySigHandler); <== Error Line
> > }
> > void *MySigHandler(int x)
> > {
> > // ...
> > }
> >
> > Error: Could not find a match for InstallSigHandler( 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

>
>



 
Reply With Quote
 
MiniDisc_2k2
Guest
Posts: n/a
 
      06-25-2003

"Victor Bazarov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Tom" <(E-Mail Removed)> wrote...
> > Lib:
> > int InstallSigHandler(void (sigHandler)(int))

>
> (a) This should be
>
> int InstallSigHandler(void (*sigHandler)(int))


Just what I was going to say...
>
> > {
> > ...
> > }
> >
> > App:
> > void MySigHandler(int);
> >
> > void main (void)
> > {
> > InstallSigHandler(&MySigHandler);

>
> (b) The '&' is unnecessary.


But it helps maintain readability.


 
Reply With Quote
 
Alexander Terekhov
Guest
Posts: n/a
 
      06-25-2003

Victor Bazarov wrote:
[...]
> > App:
> > void MySigHandler(int);
> >
> > void main (void)
> > {
> > InstallSigHandler(&MySigHandler);

>
> (b) The '&' is unnecessary.


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

regards,
alexander.
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      06-26-2003
"Christopher Parent" <(E-Mail Removed)> wrote...
> Alright, I've made some changes, and I know longer get any compilation
> errors,


You don't? Your compiler must be more forgiving than mine.

> but now I'm getting a link error. Here's what I've done:
>
> MyLibrary.C/h (This is the same as before)
> -----------
>
> int InstallSigHandler( void (*sigHandler) (int) )
> {
> ...;
> }
>
> MyProgram.C
> -----------
>
> #include MyLibrary.h


#include <MyLibrary.h>

> void MySigHandler(int);
>
> main()


int main()

> {
> InstallSigHandler(MySigHandler);
> }
>
> void MySigHandler(int x)
> {
> // ...
> }
>
> The linkage error that I'm getting is
>
> Undefined symbol first referenced in file
> int InstallSigHandler(void(*)(int)) MyProgram.o


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


 
Reply With Quote
 
MiniDisc_2k2
Guest
Posts: n/a
 
      06-26-2003
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


 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      06-26-2003

> void MySigHandler(int);


Do you want
extern "C" void MySigHandler(int);

>
> main()


must provide return value (int) for main.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
Could not connect to mail server System.Web Could not access 'CDO.Message' object. ????? Adam Knight ASP .Net 1 12-05-2005 05:38 AM
Smart pointers and member function pointers n2xssvv g02gfr12930 C++ 3 11-27-2005 10:51 AM
Error Message: Outlook Express Could Not Be Started Because Msoe.dll Could Not Be Loaded Dutch Treat Computer Support 4 06-21-2004 02:01 PM
Project could not be opened because a language-specific compiler could not be instantieted Roxanne ASP .Net 0 07-04-2003 10:22 AM



Advertisments