简体   繁体   English

模板函数引用的向量

[英]Vector of references to template functions

I have many functions defined like so : 我有很多这样定义的功能:

template<class T>
std::tuple<Matrix<T>, Matrix<T>, Matrix<T>> gaussSeidel(Matrix<T> const& A, Matrix<T> const& b, long double precision) {
    ...
}

Now, I want to hold a reference to them all in a templated vector variable, that I try to declare like so : 现在,我想在模板化的矢量变量中保留对它们的所有引用,我尝试像这样声明:

template<typename T>
std::vector<std::tuple<Matrix<T>, Matrix<T>, Matrix<T>> (&) (Matrix<T>, Matrix<T>, T)> functs {gaussSeidel<T>, jacobi<T>, richardson<T>, sor<T>, gmres<T>};

It throws many C2528 errors at instanciation ( decltype(auto) functs<long double> ) when compiling in Visual Studio, emerging all from the allocator. 在Visual Studio中进行编译时,它会在实例化时( decltype(auto) functs<long double> )引发许多C2528错误,所有错误均来自分配器。 Where am I going wrong ? 我要去哪里错了?

From what I know you need a vector of pointers to functions not references to functions. 据我所知,您需要一个指向函数的指针向量,而不是对函数的引用。 You should replace the (&) with (*) 您应将(&)替换为(*)

template<typename T>
std::vector<std::tuple<Matrix<T>, Matrix<T>, Matrix<T>> (*)(Matrix<T> const&, Matrix<T> const&, long double)> functs {gaussSeidel<T>, jacobi<T>, richardson<T>, sor<T>, gmres<T>};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM