小编Gre*_*hen的帖子

使用模板友元函数时未解决的重载函数类型

我有一个问题,我正在尝试将类模板的朋友函数填充到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;
}
Run Code Online (Sandbox Code Playgroud)

这两行都main不会编译.对于第一个,GCC抱怨:

error: conversion from '<unresolved overloaded function type>' to non-scalar type 'boost::function<double(Vec<2>, Vec<2>)>' requested
Run Code Online (Sandbox Code Playgroud)

第二行的错误似乎让我更加困惑:

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>, …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-function

3
推荐指数
1
解决办法
2805
查看次数

标签 统计

boost ×1

boost-function ×1

c++ ×1