473,546 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

"Christophe r Parent" <dj*******@yaho o.com> wrote in message
news:35******** *************** ***@posting.goo gle.com...
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);
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()
{
InstallSigHandl er(MySigHandler ); <== Error Line
or alternatively change it here:
InstallSigHandl er(&MySigHandle r);
and get rid of the * in the function declaration above.
}
void *MySigHandler(i nt x)
Change this to match the function declaration.
{
// ...
}

Error: Could not find a match for InstallSigHandl er( 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
"Christophe r Parent" <dj*******@yaho o.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 InstallSigHandl er( void (*sigHandler) (int) )
{
// ....
return ...
}
MyMain.C
--------

#include MyLibrary.h ^^^^
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.
void *MySigHandler(i nt);

main()
Should be

int 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.
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).

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.co m> wrote...
Lib:
int InstallSigHandl er(void (sigHandler)(in t))
(a) This should be

int InstallSigHandl er(void (*sigHandler)(i nt))
{
...
}

App:
void MySigHandler(in t);

void main (void)
{
InstallSigHandl er(&MySigHandle r);
(b) The '&' is unnecessary.
}

void MySigHandler(in t x)
{
...
}

This should work!
With the correction (a) it will.

Regards,
Tom

"Christophe r Parent" <dj*******@yaho o.com> wrote in message
news:35******** *************** ***@posting.goo gle.com...
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


Jul 19 '05 #4

"Victor Bazarov" <v.********@att Abi.com> wrote in message
news:vf******** ****@corp.super news.com...
"Tom" <to*@yahoo.co m> wrote...
Lib:
int InstallSigHandl er(void (sigHandler)(in t))
(a) This should be

int InstallSigHandl er(void (*sigHandler)(i nt))


Just what I was going to say...
{
...
}

App:
void MySigHandler(in t);

void main (void)
{
InstallSigHandl er(&MySigHandle r);


(b) The '&' is unnecessary.


But it helps maintain readability.
Jul 19 '05 #5

Victor Bazarov wrote:
[...]
App:
void MySigHandler(in t);

void main (void)
{
InstallSigHandl er(&MySigHandle r);


(b) The '&' is unnecessary.


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

regards,
alexander.
Jul 19 '05 #6
"Christophe r Parent" <dj*******@yaho o.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 InstallSigHandl er( void (*sigHandler) (int) )
{
...;
}

MyProgram.C
-----------

#include MyLibrary.h
#include <MyLibrary.h>
void MySigHandler(in t);

main()
int main()
{
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


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(in t);
Do you want
extern "C" void MySigHandler(in t);

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
2146
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 called function, I am using p1->find(1) which is returning a valid iterator and not going to the end. I am returning p1 from the called function. ...
4
3325
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 if so, why not? Shouldn the compiler be able to tell which of he overloaded functions to use? The second A::comp() is the one I accidently added...
12
2692
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 the word needs to be at least 2 characters long with no intervening punctuation, numbers or other non-letters. This word then needs to be lower case...
51
2504
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
2279
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
25111
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 test2(int a){cout<<"2";}
1
5550
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
2304
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 libary do I create a function where user passes this callback function? How would I define the function?
20
2201
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 think my way through what I want to do now. I don't know why - I'm fine with most other aspects of the language, but my brain goes numb when I'm...
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.