473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 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
Jul 19 '05 #1
8 5436

"Christopher Parent" <dj*******@yahoo.com> wrote in message
news:35**************************@posting.google.c 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
Jul 19 '05 #2
"Christopher Parent" <dj*******@yahoo.com> 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
Jul 19 '05 #3
"Tom" <to*@yahoo.com> 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" <dj*******@yahoo.com> wrote in message
news:35**************************@posting.google.c 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


Jul 19 '05 #4

"Victor Bazarov" <v.********@attAbi.com> wrote in message
news:vf************@corp.supernews.com...
"Tom" <to*@yahoo.com> 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.
Jul 19 '05 #5

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.
Jul 19 '05 #6
"Christopher Parent" <dj*******@yahoo.com> 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?
Jul 19 '05 #7
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
Jul 19 '05 #8
void MySigHandler(int);
Do you want
extern "C" void MySigHandler(int);

main()


must provide return value (int) for main.

Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
4
by: hall | last post by:
I accidently overloaded a static member function that I use as predicate in the std::sort() for a vector and ended up with a compiler error. Is this kind of overload not allowed for predicates and...
12
by: David W. Thorell | last post by:
I am trying to write a basic spell check function, one which has as its parameters two strings arrays, one is an article from a file source which needs to be checked for valid words, in this case...
51
by: Richard Hengeveld | last post by:
Hi all, I'm trying to understand how pointers for function parameters work. As I understand it, if you got a function like: void f(int *i) { *i = 0; }
4
by: infogoogle | last post by:
Hello, i'm having problems with the type of a template function: This code: class A {}; class B : A {}; template<class T B* fnull() { return 0; };
5
by: steven_orocos | last post by:
Hi, I'm tryin to pass a funtion as an argument in another funtion. This code works ---------------------------------- typedef void (*func)(int); void test1(int a){cout<<"1";} void...
1
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
40
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.