Call to non-constexpr function error when Bezier::Bezier<VARIABLE> initialization
Closed this issue · 4 comments
I would like to calculate Bezier in the runtime as:
Bezier::Bezier<path.rows()> cubicBezier({ }); where path.rows() is the number of 2D point. However, it does not allow me to do so. Could you help about that issue? Can't we assign this in the runtime?
Thanks in advance
What is your error message? Is path.rows()
a constant compile time expression?
error: call to non-constexpr function ‘Eigen::Index Eigen::PlainObjectBase::rows() const [with Derived =Eigen::Matrix<float, -1, 5>; Eigen::Index = long int]’
Bezier::Bezier<path.rows()> cubicBezier({ {0, 0} });
path.rows() is not a constant. My aim is basically able to decide Bezier::Bezier<some variable< in runtime
It is not possible to pass a runtime variable to as a template argument. It has to be a compile time constant expression. See for example https://en.cppreference.com/w/cpp/language/templates
I suppose you could create some templates or functions of your own to make it work:
switch(path.rows())
{
case 2:
// Call a function that explicitly uses Bezier::Bezier<2>.
case 3:
// Call a function that explicitly uses Bezier::Bezier<3>.
default:
break;
}
Although this could get messy very quickly.
I will close this for now since I consider this to be out of the library's scope. See for example this StackOverflow question which is the same as you are trying to do.