Reputation: 97
According to the standard, this should compile:
struct Y {};
template<const Y& y> struct Z {};
int main(){
Y y;
Z<y> z; // ok: no conversion and cv-qualification conversion
}
(it's taken from - http://en.cppreference.com/w/cpp/language/template_parameters).
But, it doesn't, giving this error: error: the value of ‘y’ is not usable in a constant expression
What am I missing?
Upvotes: 1
Views: 38
Reputation: 117691
You are taking a reference to a local object, which is not a constant expression. If y
was a global variable, it'd work just fine.
Upvotes: 2