
C++
亦星然
这个作者很懒,什么都没留下…
展开
-
C C++ 对二进制数逐位取一
假如二进制数为x,它的位数为n。那么想要获得它的所有为1位,可以: #include <stdio.h> int main() { int x = 0b1101101101; const int n = 10; int i; for (i = 0; i < n; i++) { if ( x & (1 << i) ) { printf("there is a 1:%d\n", i); } } return 0; } ...原创 2020-10-30 19:21:18 · 1754 阅读 · 0 评论 -
重载运算符
Box operator+(const Box&); Box为返回类型 函数名是由关键字 operator 和其后要重载的运算符符号 const Box&为参与运算的另一个参数 大多数的重载运算符可被定义为普通的非成员函数或者被定义为类成员函数。如果我们定义上面的函数为类的非成员函数,那么我们需要为每次操作传递两个参数,如下所示: Box operator+(const Box&, const Box&); 使用过程: Box3 = Box1 + Box2; .翻译 2020-10-28 18:27:37 · 220 阅读 · 0 评论