-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