作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
这似乎可行:
template<class A> struct S {
template<class B> friend S<B> f(B);
};
template<class B> S<B> f(B) {return S<B>{};}
int main() {
f(5);
}
好的,让我们做一个看似纯粹的外观更改,将 f
的定义移动到 struct
的主体中:
template<class A> struct S {
template<class B> friend S<B> f(B) {return S<B>{};}
};
int main() {
f(5);
}
突然编译开始失败:
prog.cpp: In function ‘int main()’:
prog.cpp:6:5: error: ‘f’ was not declared in this scope
f(5);
^
为什么需要在类外部定义模板友元函数才能在此代码段中工作?
是否有任何技巧可以让函数 f
在类定义的主体中定义?
我是一名优秀的程序员,十分优秀!