I have a problem where I'm trying to stuff a friend function of a class template into a boost::function
:
#include <boost/function.hpp>
template <int N>
struct Vec{
friend
double dot(Vec, Vec){}
};
template class Vec<2>; //Force multiple instantiations
template class Vec<3>;
int main()
{
boost::function<double (Vec<2>, Vec<2>)> func = dot;
double (*func1)(Vec<2>, Vec<2>) = dot;
}
Neither of the two lines in main
will compile. For the first one, GCC complains:
error: conversion from '<unresolved overloaded function type>' to non-scalar type 'boost::function<double(Vec<2>, Vec<2>)>' requested
The error for the second line seems even more confusing to me:
error: no matches converting function 'dot' to type 'double (*)(struct Vec<2>, struct Vec<2>)'
testtmpl.C:6:15: error: candidates are: double dot(Vec<2>, Vec<2>)
testtmpl.C:6:15: error: double dot(Vec<3>, Vec<3>)
I'm kind of stymied since I don't see why double dot(Vec<2>, Vec<2>)
doesn't match.
Any ideas as to what is happening here?