Cannot cout data
Guys, reffering to last post I'm trying to output data while template is instantiated
template <unsigned long N>
struct binary
{
std::cout << N;//<---------------------------------I'M TRYING HERE
static unsigned const value
= binary<N/10>::value << 1 // prepend higher bits
| N%10; // to lowest bit
but I'm getting an error:
'Error 2 error C2886: 'std::cout' : symbol cannot be used in a member using- declaration '
Thanks for help P.S. 开发者_如何学运维And could anyone explain why actually I can't do that?
I'm trying to output data while template is instantiated
Template instantiation happens at compile-time. You can't output anything at compile-time.
All you can do is calculate the value at compile-time and the output it at run-time (i.e. inside a function).
You can declare variables, and assign them values there. But something like that needs to be inside a function.
You're inside a struct not inside a method. Only there can you call functions.
精彩评论