c++ - clang 上的模棱两可的运算符重载
问题描述
我有下面的代码(尽可能简化),它无法用 clang 编译(我一直回去,3.4.1。是编译此代码的唯一版本):
// ////////////////////////////////////////////////
// Vector 3
template <typename T>
struct TVector3
{
TVector3() { }
template <class U>
TVector3<T>& operator*=(const U ) { return *this; }
//template <class U>
//TVector3<T>& operator*=(const TVector3<U>& ) { return *this; }
};
// ////////////////////////////////////////////////
// Matrix 3x3
template <typename T>
struct TMatrix3
{
TMatrix3() { }
};
template <typename T>
TVector3<T>& operator*=(TVector3<T>& v, const TMatrix3<T>& )
{
return v;
}
// ////////////////////////////////////////////////
int main()
{
TVector3<float> o;
TMatrix3<float> m;
o *= m; // the offending statement that triggers the compilation error
return 0;
}
在其他主要编译器(gcc、MSVC、ICC)上它编译(https://godbolt.org/z/99nadcMM7)。
这里发生了什么 ?
据我所知,调用不应该是模棱两可的,矩阵重载应该基于最专业的模板函数的规则(根据这篇文章:C++ 模板化函数重载规则)。
解决方案
推荐阅读
- java - Android Media Muxer 不工作 [Android/Java]
- php - 尝试创建类别和子类别下拉菜单
- mysql - MySQL with CASE WHEN 具有多个值
- angular - 侧导航无法正常工作 | 角材料 | 角 7
- angular - 自定义角度输入掩码
- javascript - 如果 div 包含某个类,window.onclick 函数不会删除类
- sql - 将包含 JSON 的 Avro 文件放入 Snowflake 上的表结构的正确方法是什么?
- pandas - 如何替换python中列名中的瑞典字符ä、å、ö?
- r - 使用 R 在 .docx 报告中创建页眉和页脚?
- reactjs - 使用泛型在 typescript 中创建 react redux 操作