[英]Vector of references to template functions
我有很多這樣定義的功能:
template<class T>
std::tuple<Matrix<T>, Matrix<T>, Matrix<T>> gaussSeidel(Matrix<T> const& A, Matrix<T> const& b, long double precision) {
...
}
現在,我想在模板化的矢量變量中保留對它們的所有引用,我嘗試像這樣聲明:
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>};
在Visual Studio中進行編譯時,它會在實例化時( decltype(auto) functs<long double>
)引發許多C2528錯誤,所有錯誤均來自分配器。 我要去哪里錯了?
據我所知,您需要一個指向函數的指針向量,而不是對函數的引用。 您應將(&)替換為(*)
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.