07 2013 档案
摘要:《高质量c++和c编程》7.4 指针参数是如何传递内存的一节中写道void GetMemory(char *p, int num) { p = (char *)malloc(sizeof(char) * num); } void Test(void) { char *str = NULL; GetMemory(str, 100); // str 仍然为 NULL strcpy(str, "hello"); // 运行错误 }无法返回内存,可以用如下方式void GetMemory2(char **p, int num) { *p = (char *)malloc(siz..
阅读全文
摘要:class A{public: A(int arg1, int arg2); ~A(); A &operator = ( A &other); A operator + ( A &other);private: int a, b;};A::A(int arg1, int arg2){ a = arg1; b = arg2;}A::~A(){}A &A::operator=( A &other){ if (this == &other) { return *this; } this->a = other.a; ...
阅读全文
摘要:c++的容器中有位对象bitset,但是个人认为最大的问题是定义是必须指定常数大小,比如bitset bit;无法实现int n = 3;bitset bit;所以我自己查了一些资料,实现了能用变量定义的Bitsclass Bits{ public: Bits(int numOfBits); virtual ~Bits(); bool Set(int arg); bool Clr(int arg); bool Test(int arg); class BitsProxy {。。。。。 ...
阅读全文