证实虚表存储与常量区
class Person {
public:
virtual void BuyTicket() { cout << "买票-全价" << endl; }
virtual void Func1()
{
cout << "Person::Func1()" << endl;
}
virtual void Func2()
{
cout << "Person::Func2()" << endl;
}
//protected:
int _a = 0;
};
class Student : public Person {
public:
virtual void BuyTicket() { cout << "买票-半价" << endl; }
private:
virtual void Func3()
{
//_b++;
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;
}
文章来源地址https://www.toymoban.com/news/detail-603935.html
文章来源:https://www.toymoban.com/news/detail-603935.html
到了这里,关于简单明了证明多态虚表是位于常量区的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!