Hello,
I'm trying to pass a pointer to a function as an argument to a
function. I'm using the LEDA graph library, but the question I have is
not directly related to the library.
The function I want to call with another function as an argument is in
a namespace called 'GraphAlgorithms'.
There I have defined a type which is a pointer to a function (see
below), a function that takes the type as a parameter and a function
with the same signature.
This is from the GraphAlgorithms.h file.
<snip>
//Defining a type with the same signature as the function to be
passed.
typedef void (*selectFunction) (ugraph&, node&, int, list<node>*,
node_array<bool>&, node_array<int>&, list<node>&);
//Define a function
void selectMinNeighboursNeighbour(ugraph&, node&, int, list<node>*,
node_array<bool>&, node_array<int>&, list<node>&);
//A function which takes a pointer to a function as an argument
ugraph& GraphAlgorithms::MinDegree(const ugraph &G, selectFunction
);
<snip>
(GraphAlgorithms is a namespace not a class)
In a different class I am trying to create an instanse of the type
'selectFunction' (the pointer to function) and assigning the function
'selectMinNeighboursNeighbour' to it. This is done in a class (which
also includes all the types from the LEDA library) with the following
code.
<snip>
//Creating the pointer and assigning a function to it.
GraphAlgorithms::selectFunction selector =
GraphAlgorithms::selectMinNeighboursNeighbour;
//Calling the function
ugraph &graph = alg->MinDegree(g, selector);
<snip>
The problem is that the compiler won't allow the assignment. The
following error message is returned
<snip>
TestClass.cc:514: no matches converting function
`selectMinNeighboursNeighbour'
to type `void (*)(class leda_ugraph&, class node_struct*&, int,
class
leda_list<node_struct*>*, class leda_node_array<bool, leda_graph>&,
class
leda_node_array<int, leda_graph>&, class leda_list<node_struct*>&)'
GraphAlgorithms.h:85: candidates are: void
GraphAlgorithms::selectMinNeighboursNeighbour(leda_ugraph&,
node_struct*&,
int, leda_list<node_struct*>*, leda_node_array<bool, leda_graph>&,
leda_node_array<int, leda_graph>&, leda_list<node_struct*>&)
<snip>
Notice that the difference in the signatures is that in the pointer I
created the 'class' keyword precedes all the types which are not built
in types.
I have no idea what is causing this. I hope that somebody knows what I
can do to fix this, and also what I have done wrong.
Thanks!
Kjartan S
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|