#include <iostream>
#include <cstring>
class Config {
public:
char name[16];
Config() { std::strcpy(name, "SystemConfig"); }
};
class Secret {
public:
int key;
Secret() { key = 0x12345678; }
virtual void shadow() {} // 增加虚函数,方便通过虚表识别类
};
int main() {
Config* c = new Config();
Secret* s = new Secret();
std::cout << "Config at: " << (void*)c << std::endl;
std::cout << "Secret at: " << (void*)s << std::endl;
// 这里设个断点
return 0;
}
编译:g++ -g heap_test.cpp -o heap_test