【发布时间】:2021-10-25 19:21:30
【问题描述】:
我无法让它工作:
template<std::size_t s, typename T>
class A;
template<std::size_t s, typename T, typename U>
A<s, T> operator *(U const lhs, A<s, T> const& rhs);
template<std::size_t s, typename T>
class A
{
// Blabla
template<typename U>
friend A<s, T> operator * <>(U const lhs, A<s, T> const& rhs);
};
编译失败并显示以下错误消息:
在主模板的声明中使用了无效的模板 ID 'operator * '。
【问题讨论】:
-
为什么
<>在类内operator*之后?你到底想做什么? -
@cigien 这是我的灵感:(web.mst.edu/~nmjxv3/articles/templates.html) 它适用于其他方法。
-
@cigien 实际上你是对的,在`operator *``之后不需要
<>。