我有一个超类,它在其构造函数中将const char *
成员设置为文本“ ”。V9k6FmI6Lw
然而,当子类读取这个成员时,它最终成为"org: \200\201\360\210"
为什么是这样?
程序代码:
Struct Json {
std::string objectId;
}
class Super {
const char * objectId;
Super( Json value) {
objectId = value.objectId.c_str();
}
}
class Duper : public Super {
Duper (Json value) : Super(value) {
}
void doSomething() {
std::cout << "Object Id is : " << objectId;
}
}
int main (){
Json value { "V9k6FmI6Lw" };
Duper object(value);
object.doSomething();
return 0;
}