Reputation: 9176
I have three template arguments to a function and am having troubles with (I think) the compiler deducing which template argument is which.
The template function is:
#include <structures/partition.h>
#include <vector>
namespace cliques
{
template <typename P, typename T, typename QF>
P find_optimal_partition_louvain(cliques::Graph<T> &my_graph,
QF quality_function)
{
P dummy;
}
}
And when I try to call it with
cliques::find_optimal_partition_louvain<cliques::DisjointSetForest>(my_new_graph, cliques::find_linearised_stability(current_markov_time));
Where template argument P should correspond to cliques::DisjointSetForest, and the normal function arguments are a templated class and a function object.
This fails with
error: no matching function for call to
find_optimal_partition_louvain(cliques::Graph<lemon::ListGraph>&,
cliques::find_linearised_stability)
However if I use a builtin type such as an int or a float for the P parameter everything compiles fine.
e.g.
cliques::find_optimal_partition_louvain<int>(my_new_graph, cliques::find_linearised_stability(current_markov_time));
So my question is what am I doing wrong here, how can I use a better inform the compiler which parameter is which, or am I completely off track?
Upvotes: 2
Views: 416
Reputation: 18562
I have tried to reproduce the error on a simple example, but I failed to do so (on gcc).
It looks as though the compiler does figure out that find_optimal_partition_louvain
is a function template. I suggest trying the following:
cliques::template find_optimal_partition_louvain<cliques::DisjointSetForest>(my_new_graph, cliques::find_linearised_stability(current_markov_time));
Otherwise, you might want to verify if the following simple example compiles fine on your compiler (because it should!):
#include <iostream>
template <class G>
struct Bar { };
namespace Foo {
template <class A, class B, class C>
A some_function(Bar<B>&, C aFunc) {
aFunc();
return A();
};
};
struct HWPrinter {
HWPrinter() { std::cout << "Hello World!" << std::endl; };
};
struct IntPrinter {
int value;
IntPrinter(int aValue) : value(aValue) { };
void operator() () { std::cout << "The integer is: " << value << std::endl; };
};
int main() {
Bar<HWPrinter> ab;
Foo::some_function<HWPrinter>(ab,IntPrinter(42));
return 0;
};
Upvotes: 0
Reputation: 9176
I hate to answer my own question but problem was that cliques::DisjointSubsetForest is actually a templated class so
cliques::find_optimal_partition_louvain<cliques::DisjointSetForest<int> >(my_new_graph, cliques::find_linearised_stability(current_markov_time));
works
Upvotes: 1
Reputation: 40859
"error: no matching function for call to ‘find_optimal_partition_louvain(cliques::Graph&, cliques::find_linearised_stability)"
It would seem that your compiler thinks that cliques::Graph is not a template.
Upvotes: 0