从前一个问题当所有逗号运算符都不作为逗号运算符?,我明白函数调用中的逗号只能充当表达式sperator.但是从下面的代码中可以看出,operator()行为类似于函数调用,而operator[]不是.
所以我有两个问题:
operator[]调用而不在operator()调用内?f(a,b)是否与任何f声明的arity或类型都不匹配,不会尝试更改逗号状态并查看是否f(a.operator,(b))导致可接受的synthax?从我的角度来看,它将是与类型转换相同的过程.代码示例:
struct A{ };
struct B {
A operator,(const B & other) const { return A(); }
};
struct C {
C(){}
C(const A & a){}
void operator[](const A & a) const {}
void operator()(const A & a) const {}
};
void f(const A & a){}
int main()
{
B x,y;
C z;
//these do no compile because ',' in a function …Run Code Online (Sandbox Code Playgroud)