-1
下面的代碼編譯在鐺細++ -std = C++ 1Y,其中如在同一克給予錯誤++ -std = C++ 1Y外部鏈接模板對象eror
#include <iostream>
using namespace std;
class Demo {
public:
Demo(){}
};
template <Demo const &ref>
void fun(){}
Demo g;
const Demo g_c;
int main(){
fun<g>();
fun<g_c>();
};
下面克錯誤++
error: the value of ‘g_c’ is not usable in a constant expression
fun<g_c>();
^
error: ‘g_c’ is not a valid template argument for type ‘const Demo&’ because object ‘g_c’ has not external linkage
fun<g_c>();
^
const Demo g_c;
有內部聯繫權嗎?這是否意味着g ++在我的分析中有bug或錯誤?
可能重複http://stackoverflow.com/問題/ 9218615 /函數模板與參考模板參數) – BartoszKP