这是我无可救药地坚持的代码片段.
template <class T, T nt>
class C;
struct base{
int i;
} b;
struct derived : base{} d;
C<base*,&d> obj;
Run Code Online (Sandbox Code Playgroud)
为什么这会给出错误could not convert template argument &d to base*?
我的代码没有编译.
int foobar()
{
// code
return 5;
}
int main()
{
int &p = foobar(); // error
// code
const int& x = foobar(); //compiles
}
Run Code Online (Sandbox Code Playgroud)
为什么添加关键字const会使代码编译?