⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch16.htm

📁 Visual C++ 6.0 21天自学教程 一本适合初学和对c++有一定基础的人学习的好书
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD>	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1"><SCRIPT LANGUAGE="JavaScript"><!--function popUp(pPage) { var fullURL = document.location; var textURL = fullURL.toString(); var URLlen = textURL.length; var lenMinusPage = textURL.lastIndexOf("/"); lenMinusPage += 1; var fullPath = textURL.substring(0,lenMinusPage); popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394'); figDoc= popUpWin.document; zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>'; zhtm += '</head>'; zhtm += '<BODY bgcolor="#FFFFFF">'; zhtm += '<IMG SRC="' + fullPath + pPage + '">'; zhtm += '<P><B>' + pPage + '</B>'; zhtm += '</BODY></HTML>'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 }//-->                                                                </SCRIPT><link rel="stylesheet" href="/includes/stylesheets/ebooks.css">	<META NAME="GENERATOR" Content="Symantec Visual Page Mac 1.1.1">	<TITLE>Teach Yourself Visual C++ 6 in 21 Days -- Ch 16 -- Creating Your Own Classes and Modules</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><H1 ALIGN="CENTER"><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM"BORDER="0"><BR>Teach Yourself Visual C++ 6 in 21 Days</H1><CENTER><P><A HREF="../ch15/ch15.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch17/ch17.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><H1 ALIGN="CENTER">- 16 -<BR>Creating Your Own Classes and Modules</H1><H1></H1><UL>	<LI><A HREF="#Heading1">Designing Classes</A>	<UL>		<LI><A HREF="#Heading2">Encapsulation</A>		<LI><A HREF="#Heading3">Inheritance</A>		<LI><A HREF="#Heading4">Visual C++ Class Types</A>	</UL>	<LI><A HREF="#Heading5">Creating Library Modules</A>	<LI><A HREF="#Heading6">Using Library Modules</A>	<UL>		<LI><A HREF="#Heading7">Creating the Library Module</A>		<LI><A HREF="#Heading8">Creating a Test Application</A>		<LI><A HREF="#Heading10">Updating the Library Module</A>	</UL>	<LI><A HREF="#Heading11">Summary</A>	<LI><A HREF="#Heading12">Q&amp;A</A>	<LI><A HREF="#Heading13">Workshop</A>	<UL>		<LI><A HREF="#Heading14">Quiz</A>		<LI><A HREF="#Heading15">Exercise</A>	</UL></UL><P><HR SIZE="4"><BR>Sometimes you need to build a set of application functionality that will be usedin an application that another programmer is working on. Maybe the functionalitywill be used in a number of applications. Another possibility is that you want toseparate some functionality from the rest of the application for organizational purposes.You might develop this separate set of functionality and then give a copy of thecode to your friend to include in his application, but then every time you make anychanges to your set of functionality, it has to be reincorporated into the otherset of application code. It would be much more practical if you could give a compiledversion of your functionality to the other programmer so that every time you updatedyour part, all you had to hand over was a new compiled file. The new file could justreplace the previous version, without having to make any changes to the other programmer'scode.</P><P>Well, it is possible to place your set of functionality into a self-containedcompiled file, link it into another programmer's application, and avoid adding anynew files to the finished application. Today, you will learn</P><P><UL>	<LI>How to design your own classes.	<P>	<LI>How to create compiled modules that can be linked into other applications.	<P>	<LI>How to include these modules into an application.</UL><H2><A NAME="Heading1"></A>Designing Classes</H2><P>You've already designed and built your own classes over the past few days, sothe basics of creating a new class is not a new topic. Why did you create these classes?Each of the new classes that you created encapsulated a set of functionality thatacted as a self-contained unit. These units consisted of both data and functionalitythat worked together to define the object.</P><P><H3><A NAME="Heading2"></A>Encapsulation</H3><P>Object-oriented software design is the practice of designing software in the sameway that everything else in the world is designed. For instance, you can consideryour car built from a collection of objects: the engine, the body, the suspension,and so on. Each of these objects consists of many other objects. For instance, theengine contains either the carburetor or the fuel injectors, the combustion chamberand pistons, the starter, the alternator, the drive chain, and so on. Once again,each of these objects consists of even more objects.</P><P>Each of these objects has a function that it performs. Each of these objects knowshow to perform its own functions with little, if any, knowledge of how the otherobjects perform their functions. Each of the objects knows how it interacts withthe other objects and how they are connected to the other objects, but that's aboutall they know about the other objects. How each of these objects work internallyis hidden from the other objects. The brakes on your car don't know anything abouthow the transmission works, but if you've got an automatic transmission, the brakesdo know how to tell the transmission that they are being applied, and the transmissiondecides how to react to this information.</P><P>You need to approach designing new classes for your applications in the same way.The rest of the application objects do not need to know how your objects work; theyonly need to know how to interact with your objects. This principle, called <I>encapsulation</I>,is one of the basic principles of object-oriented software.</P><P><H3><A NAME="Heading3"></A>Inheritance</H3><P>Another key principle of object-oriented software design is the concept of <I>inheritance</I>.An object can be inherited from another object. The descendent object inherits all

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -