我有一个C++类,它具有以下接口:
class F {
public:
F(int n, int d);
// no other constructors/assignment constructors defined
F& operator *= (const F&);
F& operator *= (int);
int n() const;
int d() const;
};
Run Code Online (Sandbox Code Playgroud)
我有以下代码:
const F a{3, 7};
const F b{5, 10};
auto result = F{a} *= b; // How does this compile?
Run Code Online (Sandbox Code Playgroud)
在Visual Studio(VS)2013下,注释行编译时没有错误.在VS2015下,产生错误C2678:
error C2678: binary '*=': no operator found
which takes a left-hand operand of type 'const F'
(or there is no acceptable conversion)
note: could be 'F &F::operator …Run Code Online (Sandbox Code Playgroud)