C++ 指向外部函数的静态函数指针

C++ 指向外部函数的静态函数指针,c++,function,pointers,static,external,C++,Function,Pointers,Static,External,是否可以创建指向外部函数的静态函数指针 我尝试了几种可能的解决方案,但都无效 代码如下: template <class T> struct SIMD_type_traits { typedef T type; }; template <> struct SIMD_type_traits<int> { typedef __m128i type; }; template <class T, class S = typename

是否可以创建指向外部函数的静态函数指针

我尝试了几种可能的解决方案,但都无效

代码如下:

template <class T>
    struct SIMD_type_traits {
    typedef T type;
};

template <>
struct SIMD_type_traits<int> {
    typedef __m128i type;
};

template <class T, class S = typename SIMD_type_traits<T>>
class SIMD_traits{
public:
    typedef T element_type;
    typedef typename S::type simd_type;
    typedef simd_type(*binaryFunction)(simd_type, simd_type);
    const static binaryFunction add;
};

static void noop(){
    throw std::string("no specialization for SIMD function");
}

template <class T, class S>
const typename SIMD_traits<T, S>::binaryFunction SIMD_traits<T, S>::add = ((SIMD_traits<T, S>::binaryFunction)noop);

template <>
const typename SIMD_traits<int>::binaryFunction SIMD_traits<int>::add = &_mm_add_epi32;

我知道,函数
\u mm\u add\u epi32
是外部函数,函数地址将在链接时解析,但这是否可行?

您尝试过的几种可能的解决方案是什么?这些不是外部函数,但是由编译器内联。您是否尝试生成全局静态函数指针?如果这两个都是单独编译单元中的全局变量,则链接器将无法解析实例化顺序。@BoPersson,MSVC是否应该拒绝编译代码,而不是失败durink链接?@Ignacio Bertacchini:我尝试了schwarz计数器,并将初始化放入cpp文件和其他文件中。。。
1>main.obj : error LNK2001: unresolved external symbol _mm_add_epi32
1>....obj : error LNK2001: unresolved external symbol _mm_add_epi32
1>c:\....exe : fatal error LNK1120: 1 unresolved externals