我有一些这样的功能:
void MClass::GetS(char* buf, int max) const {
char *temp = new char[max];
temp[max] = '\0';
for (int i = 0; i < max - 1; i++)
temp[i] = src[i]; // src is class member (char *)
buf = temp; // buf is null after this o.O
}
因此,我无法更改此函数中的 buf 值。为什么会发生?