int p is not a constant expression in lpNorm<p>
问题 I wrote this function template <typename T> double norm(const T & v, const int p) { return v.template lpNorm<p>(); } but it doesn't work and gives the error: error: 'p' is not a constant expression return v.template lpNorm<p>(); ^ I seem to think that the compiler expects p to be known at compile time whereas my p is dynamic. Possibly related: Why is this not a constant expression? Non-type template argument is not a constant expression How can I fix this? 回答1: You can partially do it with a