q**p 发帖数: 147 | 3 1,
void newBuffer(char* outBuffer, size_t sz) {
outBuffer = new char[sz];
}
int main() {
const char* kung = "KUNG";
char* foo;
size_t len = strlen(kung);
newBuffer(foo, len);
memset(foo, 0, len+1);
strncpy(foo, kung, len);
cout << foo << endl;
}
这个可以编译,但是有bug,运行之后知道是foo的问题,具体不太明白,求指点
2,
B is a class inherited from A.
B *myPointer = new B();
A *myOtherPointer = myPointer;
printf(“%x”, myPointer);
printf(“%x”, myOtherPointer);
这段代码的两个... 阅读全帖 |
|