伙计们,引用last post我正在尝试在实例化模板时输出数据
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
但是我收到一个错误:
'错误 2 error C2886: 'std::cout' : 符号不能在使用声明的成员中使用 '
感谢帮助 附言 谁能解释为什么实际上我不能那样做?
最佳答案
I'm trying to output data while template is instantiated
模板实例化发生在编译时。您无法在编译时输出任何内容。
您所能做的就是在编译时计算值并在运行时输出它(即在函数内部)。
关于c++ - 无法统计数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2483598/