简体   繁体   中英

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. 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>};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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