我想想都觉得好笑。例如,任何 C 编译器都必须区分 int *c; 和 double d = (int) f * (float) g;。在前一种情况下,* 表示 c 是一个指向 int 的指针,而在后一种情况下,它是一个乘法运算符。虽然没有导出到编译器本身之外,但 C 似乎具有运算符重载功能。 C++ 将其导出到编译器之外?
I'm amused thinking about it. Any C compiler for example, must tell between an int *c; and double d = (int) f * (float) g;. In the former case, * indicates c is a pointer to int while in the latter case it is a multiplication operator. Though not exported outside the compiler itself, C appears to have operator overloading feature. C++ exported it outside the compiler?
I am sure other languages like Java should have some mechanism to tell + or * or such operators when they are used between various combinations and permutations of the types of the operands.
发布评论
评论(1)
我想想都觉得好笑。例如,任何 C 编译器都必须区分
int *c;
和double d = (int) f * (float) g;
。在前一种情况下,* 表示 c 是一个指向 int 的指针,而在后一种情况下,它是一个乘法运算符。虽然没有导出到编译器本身之外,但 C 似乎具有运算符重载功能。 C++ 将其导出到编译器之外?我确信像 Java 这样的其他语言应该有某种机制来告诉 + 或 * 或此类运算符在操作数类型的各种组合和排列之间使用时的情况。
I'm amused thinking about it. Any C compiler for example, must tell between an
int *c;
anddouble d = (int) f * (float) g;
. In the former case, * indicates c is a pointer to int while in the latter case it is a multiplication operator. Though not exported outside the compiler itself, C appears to have operator overloading feature. C++ exported it outside the compiler?I am sure other languages like Java should have some mechanism to tell + or * or such operators when they are used between various combinations and permutations of the types of the operands.