/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:text.cpp
*作者:汤善晔
*完成日期:2016年8月20日
*版本号:v1.0
*/
<code class=" hljs lasso" style="display: block; padding: 0.5em; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">class Animal { <span class="hljs-keyword" style="color: rgb(0, 0, 136);">public</span>: virtual <span class="hljs-literal" style="color: rgb(0, 102, 102);">void</span> cry() { cout<span class="hljs-subst"><<</span><span class="hljs-string" style="color: rgb(0, 136, 0);">"不知哪种动物,让我如何学叫?"</span><span class="hljs-subst"><<</span>endl; } }; int main( ) { Animal <span class="hljs-subst">*</span>p; p <span class="hljs-subst">=</span> <span class="hljs-literal" style="color: rgb(0, 102, 102);">new</span> Animal(); p<span class="hljs-subst">-></span>cry(); Mouse m1(<span class="hljs-string" style="color: rgb(0, 136, 0);">"Jerry"</span>,<span class="hljs-string" style="color: rgb(0, 136, 0);">'m'</span>); p<span class="hljs-subst">=&</span>m1; p<span class="hljs-subst">-></span>cry(); Mouse m2(<span class="hljs-string" style="color: rgb(0, 136, 0);">"Jemmy"</span>,<span class="hljs-string" style="color: rgb(0, 136, 0);">'f'</span>); p<span class="hljs-subst">=&</span>m2; p<span class="hljs-subst">-></span>cry(); Cat c1(<span class="hljs-string" style="color: rgb(0, 136, 0);">"Tom"</span>); p<span class="hljs-subst">=&</span>c1; p<span class="hljs-subst">-></span>cry(); Dog d1(<span class="hljs-string" style="color: rgb(0, 136, 0);">"Droopy"</span>); p<span class="hljs-subst">=&</span>d1; p<span class="hljs-subst">-></span>cry(); Giraffe g1(<span class="hljs-string" style="color: rgb(0, 136, 0);">"Gill"</span>,<span class="hljs-string" style="color: rgb(0, 136, 0);">'m'</span>); p<span class="hljs-subst">=&</span>g1; p<span class="hljs-subst">-></span>cry(); <span class="hljs-keyword" style="color: rgb(0, 0, 136);">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102);">0</span>; }</code><code class=" hljs lasso" style="display: block; padding: 0.5em; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><img src="https://img-blog.csdn.net/20160821214354963?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /> </code><code class=" hljs lasso" style="display: block; padding: 0.5em; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"> </code>