证实虚表存储与常量区
class Person {
public:
virtual void BuyTicket() { cout << "买票-全价" << endl; }
virtual void Func1()
{
cout << "Person::Func1()" << endl;
}
virtual void Func2()
{
cout << "Person::Func2()" << endl;
}
int _a = 0;
};
class Student : public Person {
public:
virtual void BuyTicket() { cout << "买票-半价" << endl; }
private:
virtual void Func3()
{
cout << "Student::Func3()" << endl;
}
protected:
int _b = 1;
};
void Func(Person& p)
{
p.BuyTicket();
}
int main()
{
Person ps;
Student st;
int a = 0;
printf("栈区:%p\n", &a);
int* b = new int;
printf("堆区:%p\n", b);
static int c = 0;
printf("静态区:%p\n", &c);
const char* s = "hello world";
printf("常量区:%p\n", s);
printf("判断:%p\n", *((int*)&ps));
printf("判断:%p\n", *((int*)&st));
return 0;
}