🔥个人主页:Quitecoder 🔥专栏:c++笔记仓 朋友们大家好,通过本篇文章,来详细理解多态的内容 1.多态的定义及实现 多态的基本概念:多态指的是对象可以通过指向它们的基类的引用或指针被操纵,同时还能保持其派生类部分的特性。将派生类对象当作基类对象来对待,这允许不同类的对象响应相同的消息以不同的方式,换句话说,同一个接口,使用不同的实例而执行不同操作 比如买票,普通人买票时,是全价买票;学生买票时,是半价买票 class Person { public: virtual void BuyTicket() { cout << "买票-全价" << endl; } }; class Student : public Person { public: virtual void BuyTicket() { cout << "买票-半价" << endl; } }; void Func(Person& p) { p.BuyTicket(); } int main() { Person ps; Student st; Func(ps); Func(st); return 0; }...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with Person
Contact Person, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack