在C ++中定义运算符** [英] Define operator ** in C++
本文介绍了在C ++中定义运算符**的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何定义运算符**
,使其可以执行2个数字的幂运算.例如2 ** 3
.答案应为8.
How can I define operator **
such that it can perform exponentiation of 2 numbers . eg 2 ** 3
. It should give answer as 8.
或者间接地,有什么方法可以通过运算符重载而不是#define
宏来做到这一点?
Or Indirectly is there any way I can do this with operator overloading instead of #define
macros ?
推荐答案
您不能.您只能重载现有的运算符,而不能重载内置类型.
You can't. You can only overload existing operators, and not for built in types.
这篇关于在C ++中定义运算符**的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文