简体   繁体   中英

Write function utilizing function argument's template argument

I want to write a function that takes an Eigen Spline , which is a templated class

Spline<typename _Scalar, int _Dim, int _Degree>

Is it possible (and how would I) to write a function which is not a member function of the Spline class that accepts a generic Spline and makes use of the _Scalar, _Dim, and _Degree variables? They are public enum s and a typedef .

Yes, write a function template:

template <typename T, int DIM, int DEG>
void foo(const Spline<T, DIM, DEG>& spline);

Note that I have removed all the names with leading underscores. Those are reserved names and it is undefined behaviour to use them. It seems Eigen is being naughty in this respect.

Make it a template function itself:

template<typename _Scalar, int _Dim, int _Degree>
void myFunction(Spline<_Scalar, _Dim, _Degree> &spline) {
  // do stuff...
}

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