Polymorphism in c
1 / 13

Polymorphism in C++ - PowerPoint PPT Presentation

  • Uploaded on

Polymorphism in C++. 200413287 ManYan 200413283 WangHengXin. P in C++ 1.1. In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts. For example, the + (plus) operator in C++:

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' Polymorphism in C++' - deacon-cline

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Polymorphism in c

Polymorphism in C++

200413287 ManYan

200413283 WangHengXin

P in C++ 1.1

What is polymorphism

In programming languages, polymorphism means that some code or operations or objects behave differently in different contexts.

For example, the + (plus) operator in C++:

4 + 5 <-- integer addition

3.14 + 2.0 <-- floating point addition

s1 + "bar" <-- string concatenation!

In C++, that type of polymorphism is called overloading.

Typically, when the term polymorphism is used with C++, however, it refers to using virtual methods, which we'll discuss shortly.

What is polymorphism (English).2.1

What is polymorphism?

Explain polymorphism in c in chinese
Explain polymorphism in C++ in Chinese

  • Polymorphism泛指虚函数与多态,中国IT界称之为多型与虚拟.

  • 如果你期望派生类重新定义一个成员函数,那么你应该在基类中把此函数设为virtual。以单一指令调用不同函数,这种性质称为Polymorphism。虚拟函数是C++语言的Polymorphism性质以及动态邦定的关键。既然抽象类中的虚函数不打算被调用,我们就不应该定义它,应该把它设为纯虚函数(在函数生命后面加上“=0”即可)。我们可以说,拥有纯虚函数者为抽象类(abstract class),以别于所谓的具体类(concrete class)。抽象类不能产生出对象实例,但是我们可以拥有指向抽象类的指针,以便于操作抽象类的各个派生类。虚函数派生下去仍为虚函数,而且可以省略virtual关键词。

    What is polymorphism (Chinese).2.2

Why use polymorphism in c
Why use polymorphism in C++

We study C++ difficulty at paradigm shift.If we can’t design classes.We just use other programmer’s classes.This is paradigm shift.

Especially,The MFC(or OWL or VCL)programmer.

When we use application framework.Do you know that What’s the connection in your code andframework?Where is the value of framework?Why the framework can use in our class types.When the programmer design framework.They don’t know our programmers will use their product.

  • P in C++ 3.1

Why use polymorphism in c1
Why use polymorphism in C++

  • It’s the power of polymorphism in direction of thing.

  • If you can’t use polymorphism and generalizatio-

    n,You’ll get nothing in C++.

  • P in C++ 3.2

Why use polymorphism in c in chinese
Why use polymorphism in C++ in Chinese

  • C++ 的学习难度在于 “paradigm shift”(思考模式的移转).b不说自己设计 classes ,仅仅使用别人的 classes,就已是一种思考模式和行为模式的转移。MFC(或 OWL 或 VCL)programmer 必然甚能够领略并体会这层意思。

  • 当我们使用所谓的application framework(一种大型的、凝聚性强的、有着物件导向公共基础建设的 class library),你的代码和 framework之间究竟是怎样的关系呢?framework提供的一大堆可改写的虚拟函式的意义与价值究竟在哪里?为什么framework所设计的种种美好性质以及各式各样的演算法竟然可以应用于我们自己设计的class types 上呢?framework 被设计时,设计师并不知道我们的存在.

  • P in C++ 3.3 in chinese

Why use polymorphism in c in chinese1
Why use polymorphism in C++ in Chinese

  • 这个时候正是体现物件导向中的多(polymorphism)的威力的时候.

  • 能够把新思维模式的威力发挥得最淋漓尽致的,当然是物件导向的 polymorphism(多型)和 generalization(泛型)。如果你没有使用这两项特性,那你不会在C++的中获得更好东西 。

  • P in C++ 3.4 in chinese

Study polymorphism s importance in c
Study polymorphism’s importancein C++

  • After begins studies C++ grammar (syntax),We should attempt to experience polymorphism as soon as possible.

  • The growth, is transforms between low-order (object model) and higher order (polymorphism).Only then can arrive the higher position step, but is not mediocre for lower C++ syntax

  • The last aim is polymorphism in C++!

  • P in C++ 3.5

Study polymorphism s importance in c1
Study polymorphism’s importancein C++

  • 初学 C++ 语法(syntax)之后,我们应该尽快尝试体验 polymorphism(也就是虚拟函式的运用).

  • 成长,是在高阶(polymorphism)和低阶(object model)之间反覆尝试,才能够达到到更高的位阶,而不是平平庸庸于中阶(C++ syntax).

  • 学习C++的最终目的是polymorphism!

  • P in C++ 3.6 in chinese

Polymorphism in object oriented practice oop
Polymorphism in object oriented practice(OOP)

  • In object oriented practice, it is common that class objects are manipulated through a pointer or reference to an abstract base class. The abstract base class hence defines an interface to all the classes that are derived from it. Note that the abstract base class itself cannot be instantiated, and serves to provide another level of separation between interface specification (in abstact base class) and implementation (in derived classes).

  • P in C++ 4.1

What is an example of polymorphism
What is an example of polymorphism?

  • One common polymorphic amphibian is the Red-backed Salamander. Most have the namesake red stripe down their back, but some are "lead-backed" - with a grey stripe. There is even a variation that is more red, nearly the entire body is red.They are all still considered the same species and can interbreed

  • P in C++ 4.2

Summary polymorphism in c
Summary Polymorphism in C++

  • This also brings in the concept of late binding (run time binding), since the above association to the area member function can only be done at run time. The compiler will have to insert extra code to do the late binding, which adds in a little runtime overhead. For embedded systems with very constrained resources, late binding may introduce unacceptable overheads. In most systems with reasonable resources, this may not be a significant problem, but it is important to be aware of the impact of using this advanced feature of C++.

  • P in C++ 5.1