クラステンプレートのフレンド関数をに詰め込もうとしているところに問題があります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;
}
の 2 行はどちらもmain
コンパイルされません。最初のものについて、GCC は不平を言います:
error: conversion from '<unresolved overloaded function type>' to non-scalar type 'boost::function<double(Vec<2>, Vec<2>)>' requested
2行目のエラーは、私にはさらに混乱しているようです:
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>)
一致しない理由がわからないので、ちょっと困っていますdouble dot(Vec<2>, Vec<2>)
。
ここで何が起こっているかについてのアイデアはありますか?