我希望以下代码可以工作,但我收到了一个编译错误:
Run Code Online (Sandbox Code Playgroud)error C2975: 'n' : invalid template argument for 'foo', expected compile-time constant expression
#include <iostream>
using namespace std;
template<int N>
struct foo
{
    foo() { cout << N << endl; }
};
int main()
{
    foo< __LINE__ > f;
}
为什么会这样?我__LINE__会在模板实例化之前粘贴行号吗?
如果我想这样做,我应该引入一个static const int来保存行号或是否有标准解决方案?
Mac*_*cky 13
适用于VS 2010 10.0.40219.1 SP1Rel和Ideone
但MSDN提到了导致C2975的问题,如果__LINE__在带有编译器选项的模板中使用/ZI:MSDN C2975
编辑:对不起,我挂了德语版,英语在这里
| 归档时间: | 
 | 
| 查看次数: | 1142 次 | 
| 最近记录: |