使用gcc編譯以下代碼時,出現錯誤:'i'不能出現在常量表達式中。爲什麼這個const參數不能匹配一個非類型的模板參數?
這是爲什麼?
#include <iostream>
using namespace std;
template<int p>
class C
{
public:
void test();
};
template<int p>
void C<p>::test()
{
p = 0;
}
char const *const p = "hello";
int main()
{
const int i = (int)p;
C<i> c;
}
您不能將值賦給模板參數'p = 0'。 – 2012-08-16 04:18:45