我编写了一个简单的C++类示例,其中包含1个非参数构造函数,1个参数构造函数,2个复制构造函数,1个赋值运算符和1个加号运算符.
class Complex {
protected:
float real, img;
public:
Complex () : real(0), img(0) {
cout << "Default constructor\n";
}
Complex (float a, float b) {
cout << "Param constructor" << a << " " << b << endl;
real = a;
img = b;
}
// 2 copy constructors
Complex( const Complex& other ) {
cout << "1st copy constructor " << other.real << " " << other.img << endl;
real = other.real;
img = other.img;
}
Complex( Complex& …Run Code Online (Sandbox Code Playgroud) 我坚持这个问题:假设我们有32位整数,写一个C函数来计算从左边开始的连续1位的数量.例如:
leftCount(0xFF000000) = 8
leftCount(0x0FFFFFFF) = 0 (because the number starts with 0)
leftCount(-1) = 32
Run Code Online (Sandbox Code Playgroud)
在函数中,我被允许使用逻辑运算符,如!〜&^ | + << >>
不允许循环和条件结构.
谢谢