There is this code:
#include <iostream>
template<const double& f>
void fun5(){
std::cout << f << std::endl;
}
int main()
{
const double dddd = 5.0;
fun5<dddd>();
return 0;
}
Compiler error during compilation:
$ g++ klasa.cpp -o klasa
klasa.cpp: In function ‘int main()’:
klasa.cpp:11:10: error: ‘dddd’ cannot appear in a constant-expression
klasa.cpp:11:16: error: no matching function for call to ‘fun5()’
klasa.cpp:11:16: note: candidate is:
klasa.cpp:4:6: note: template<const double& f> void fun5()
Why placing 'dddd' as template parameter doesn't work and what should be done to make it work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…