Consider the following code:
static constexpr int make_const(const int i){
return i;
}
void t1(const int i)
{
constexpr int ii = make_const(i); // error occurs here (i is not a constant expression)
std::cout<<ii;
}
int main()
{
t1(12);
}
Why I have an error on make_const call?
UPDATE
But this one works:
constexpr int t1(const int i)
{
return make_const(i);
}
However, this not:
template<int i>
constexpr bool do_something(){
return i;
}
constexpr int t1(const int i)
{
return do_something<make_const(i)>(); // error occurs here (i is not a constant expression)
}
See Question&Answers more detail:os