亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch13.htm

?? 21天學會VC的英文版
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
Your Own Classes and Modules.&quot; The other things that you need to do are giveyour class a name and specify the base class from which it will be inherited.</P><P>For your sample application, because the form that you created has informationabout a person, you might want to call your class something like CPerson. To be ableto hold your class in the object array, you need to give it CObject as the base class.Just like on Day 10, the New Class dialog will claim that it cannot find the headerwith the base class in it and that you need to add this. Well, it's already included,so you can ignore this message. (On Day 16, you'll learn when you need to pay attentionto this message.)</P><P>Once you create your new class, you'll need to add the variables for holding thedata elements that will be displayed on the screen for the user. Following good object-orienteddesign, these variables will all be declared as private variables, where they cannotbe directly manipulated by other classes. The variable types should match the variabletypes of the variables that are attached to the window controls in the view class.</P><P>With the sample application you are creating, you need to add the variables inTable 13.3.</P><P><H4>TABLE 13.3. CLASS VARIABLES FOR THE CPerson CLASS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">			<H4>Name		</TD>		<TD ALIGN="LEFT">			<H4>Type		</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">m_bEmployed		</TD>		<TD ALIGN="LEFT">BOOL		</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">m_iAge		</TD>		<TD ALIGN="LEFT">int		</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">m_sName		</TD>		<TD ALIGN="LEFT">CString		</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">m_iMaritalStatus		</TD>		<TD ALIGN="LEFT">int		</TD>	</TR></TABLE><BLOCKQUOTE>	<P><HR><STRONG>NOTE:</STRONG> An inline function is a short C++ function in which, when the application	is being compiled, the function body is copied in place of the function call. As	a result, when the compiled application is running, the function code is executed	without having to make a context jump to the function and then jump back once the	function has completed. This reduces the overhead in the running application, increasing	the execution speed slightly, but also makes the resulting executable application	slightly larger. The more places the inline function is called, the larger the application	will eventually get. For more information on inline functions, consult Appendix A,	&quot;C++ Review.&quot;<HR></BLOCKQUOTE><H4>Adding Methods for Reading and Writing Variables</H4><P>Once you create your class, you need to provide a means for reading and writingto the variables in the class. One of the easiest ways to provide this functionalityis to add inline functions to the class definition. You create a set of inline functionsto set each of the variables and then make another set for retrieving the currentvalue of each variable.</P><P>If you want to implement the Get and Set variable functions for your CPerson classin the sample application that you are building, edit the Person.h header file, addingthe lines in Listing 13.4.</P><P><H4>LISTING 13.4. THE Get AND Set INLINE FUNCTION DECLARATIONS.</H4><PRE> 1: class CPerson : public CObject 2: { 3: public: 4:     // Functions for setting the variables 5:     void SetEmployed(BOOL bEmployed) { m_bEmployed = bEmployed;} 6:     void SetMaritalStat(int iStat) { m_iMaritalStatus = iStat;} 7:     void SetAge(int iAge) { m_iAge = iAge;} 8:     void SetName(CString sName) { m_sName = sName;} 9:     // Functions for getting the current settings of the variables10:     BOOL GetEmployed() { return m_bEmployed;}11:     int GetMaritalStatus() { return m_iMaritalStatus;}12:     int GetAge() {return m_iAge;}13:     CString GetName() {return m_sName;}14:     CPerson();15:     virtual ~CPerson();16: 17: private:18:     BOOL m_bEmployed;19:     int m_iMaritalStatus;20:     int m_iAge;21:     CString m_sName;22: };</PRE><P>After you have the methods for setting and retrieving the values of the variablesin your custom class, you'll probably want to make sure that the variables are initializedwhen the class is first created. You can do this in the class constructor by settingeach of the variables to a default value. For instance, in your sample application,you add the code in Listing 13.5 to the constructor of the CPerson class.</P><P><H4>LISTING 13.5. THE CPerson CONSTRUCTOR.</H4><PRE>1: CPerson::CPerson()2: {3:     // Initialize the class variables4:     m_iMaritalStatus = 0;5:     m_iAge = 0;6:     m_bEmployed = FALSE;7:     m_sName = &quot;&quot;;8: }</PRE><P><H4>Serializing the Class</H4><P>After you have your custom class with all variables defined and initialized, youneed to make the class serializable. Making your class serializable involves threesteps. The first step is adding the Serialize function to the class. This functionwrites the variable values to, and reads them back from, the CArchive object usingC++ streams. The other two steps consist of adding the DECLARE_SERIAL and IMPLEMENT_SERIALmacros. Once you add these elements, your custom class will be serializable and readyfor your application.</P><P>To add the Serialize function to your custom class, add a member function throughthe Class View tab in the workspace pane. Specify the function type as void, thefunction declaration as Serialize(CArchive &amp;ar), and the access as public andcheck the Virtual check box. This should add the Serialize function and place youin the editor, ready to flesh out the function code.</P><P>In the Serialize function, the first thing you want to do is to call the ancestor'sSerialize function. When you call the ancestor's function first, any foundation informationthat has been saved is restored first, providing the necessary support for your classbefore the variables in your class are restored. Once you call the ancestor function,you need to determine whether you need to read or write the class variables. Youcan do this by calling CArchive's IsStoring method. This function returns TRUE ifthe archive is being written to and FALSE if it's being read from. If the IsStoringfunction returns TRUE, you can use C++ I/O streams to write all your class variablesto the archive. If the function returns FALSE, you can use C++ streams to read fromthe archive. In both cases, you must be certain to order the variables in the sameorder for both reading and writing. If you need more information about C++ streams,see Appendix A.</P><P>An example of a typical Serialize function for your sample custom class is shownin Listing 13.6. Notice that the CPerson variables are in the same order when writingto and reading from the archive.</P><P><H4>LISTING 13.6. THE CPerson.Serialize FUNCTION.</H4><PRE> 1: void CPerson::Serialize(CArchive &amp;ar) 2: { 3:     // Call the ancestor function 4:     CObject::Serialize(ar); 5:  6:     // Are we writing? 7:     if (ar.IsStoring()) 8:         // Write all of the variables, in order 9:         ar &lt;&lt; m_sName &lt;&lt; m_iAge &lt;&lt; m_iMaritalStatus &lt;&lt; m_bEmployed;10:     else11:         // Read all of the variables, in order12:         ar &gt;&gt; m_sName &gt;&gt; m_iAge &gt;&gt; m_iMaritalStatus &gt;&gt; m_bEmployed;13: }</PRE><P>Once you have the Serialize function in place, you need to add the macros to yourcustom class. The first macro, DECLARE_SERIAL, needs to go in the class header andis passed the class name as its only argument.</P><P>For example, to add the DECLARE_SERIAL macro to the custom CPerson class in yoursample application, you add the macro just below the start of the class declaration,where it will receive the default access for the class. You specify the class name,CPerson, as the only argument to the macro, as in Listing 13.7.</P><BLOCKQUOTE>	<P><HR><STRONG>NOTE:</STRONG> The default access permission for functions and variables in C++	classes is public. All functions and variables that are declared before the first	access declaration are public by default. You could easily add all of the public	class functions and variables in this area of the class declaration, but explicitly	declaring the access permission for all functions and variables is better practice--because	that way, there is little to no confusion about the visibility of any of the class	functions or variables.<HR><BR>	</P>	<P><HR><STRONG>NOTE:</STRONG> Most C++ functions need a semicolon at the end of the line of code.	The two serialization macros do not, due to the C preprocessor, which replaces each	of the macros with all of the code before compiling the application. It doesn't hurt	to place the semicolons there; they are simply ignored.<HR></BLOCKQUOTE><H4>LISTING 13.7. THE SERIALIZED CPerson CLASS DECLARATION.</H4><PRE> 1: class CPerson : public CObject 2: { 3:     DECLARE_SERIAL (CPerson) 4: public: 5:     // Functions for setting the variables 6:     void SetEmployed(BOOL bEmployed) { m_bEmployed = bEmployed;} 7:     void SetMaritalStat(int iStat) { m_iMaritalStatus = iStat;} 8:     void SetAge(int iAge) { m_iAge = iAge;} 9:     void SetName(CString sName) { m_sName = sName;}10:     // Functions for getting the current settings of the variables11:     BOOL GetEmployed() { return m_bEmployed;}12:     int GetMaritalStatus() { return m_iMaritalStatus;}13:     int GetAge() {return m_iAge;}14:     CString GetName() {return m_sName;}15:     CPerson();16:     virtual ~CPerson();17: 18: private:19:     BOOL m_bEmployed;20:     int m_iMaritalStatus;21:     int m_iAge;22:     CString m_sName;23: };</PRE><BLOCKQUOTE>	<P><HR><STRONG>NOTE:</STRONG> In practice, if you read a file that was written using a previous	version of the Serialize function in your class, your application will raise an exception,	which you can then catch using standard C++ exception-handling techniques. This allows	you to add code to your application to recognize and convert files created with earlier	versions of your application. For information on C++ exception handling, see Appendix	A.<HR></BLOCKQUOTE><P>To complete the serialization of your custom class, you need to add the IMPLEMENT_SERIAL macro to the class definition. The best place to add this macro is beforethe constructor definition in the CPP file containing the class source code. Thismacro takes three arguments: the custom class name, the base class name, and theversion number. If you make any changes to the Serialize function, you should incrementthe version number argument to the IMPLEMENT_SERIAL macro. This version number indicateswhen a file was written using a previous version of the Serialize function and thusmay not be readable by the current version of the application.</P><P>To add the IMPLEMENT_SERIAL macro to your sample application, add it into thePerson.cpp file just before the CPerson class constructor. Pass CPerson as the firstargument (the class name), CObject as the second argument (the base class), and 1as the version number, as in Listing 13.8.</P><P><H4>LISTING 13.8. THE IMPLEMENT_SERIAL MACRO IN THE CPerson CODE.</H4><PRE> 1: // Person.cpp: implementation of the CPerson class. 2: // 3: ////////////////////////////////////////////////////////////////////// 4:  5: #include &quot;stdafx.h&quot; 6: #include &quot;Serialize.h&quot; 7: #include &quot;Person.h&quot; 8:  9: #ifdef _DEBUG10: #undef THIS_FILE11: static char THIS_FILE[]=__FILE__;12: #define new DEBUG_NEW13: #endif14: 15: IMPLEMENT_SERIAL (CPerson, CObject, 1)16: //////////////////////////////////////////////////////////////////////17: // Construction/Destruction18: //////////////////////////////////////////////////////////////////////19: 20: CPerson::CPerson()21: {22:     // Initialize the class variables23:     m_iMaritalStatus = 0;24:     m_iAge = 0;25:     m_bEmployed = FALSE;26:     m_sName = &quot;&quot;;27: }</PRE><P><H3><A NAME="Heading9"></A>Building Support in the Document Class</H3><P>When you build a form-based application, where the form on the window is the primaryplace for the user to interact with the application, there is an unstated assumptionthat your application will allow the user to work with a number of records. Thismeans that you need to include support for holding and navigating these records.The support for holding the records can be as simple as adding an object array asa variable to the document class, as you did back on Day 10. This allows you to addadditional record objects as needed. The navigation could be a number of functionsfor retrieving the first, last, next, or previous record objects. Finally, you needinformational functionality so that you can determine what record in the set theuser is currently editing.</P><P>To hold and support this functionality, the document class will probably needtwo variables, the object array and the current record number in the array. Thesetwo variables will provide the necessary support for holding and navigating the recordset.</P><P>For your example, add the two variables for supporting the record set of CPersonobjects as listed in Table 13.4. Specify private access for both variables.</P><P><H4>TABLE 13.4. DOCUMENT CLASS VARIABLES.</H4><P><TABLE BORDER="1">

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久国产尿小便嘘嘘尿| 91福利精品第一导航| 欧美电影精品一区二区 | 91精品国产综合久久福利软件| 国产精品久久毛片av大全日韩| 香蕉加勒比综合久久| 欧美一区二区视频在线观看| 午夜伦欧美伦电影理论片| 在线成人午夜影院| 久久精工是国产品牌吗| 国产日产欧美一区二区视频| 国产99久久精品| 亚洲精品国产第一综合99久久| 欧美日韩dvd在线观看| 婷婷综合在线观看| 久久久久久亚洲综合影院红桃| 国产成a人亚洲精品| 日韩中文字幕区一区有砖一区| 精品国产成人系列| eeuss鲁片一区二区三区| 亚洲一级电影视频| 久久色中文字幕| 欧美在线免费观看亚洲| 国产成人三级在线观看| 亚洲一区二区视频在线观看| www激情久久| 欧美精品乱人伦久久久久久| 国产在线视视频有精品| 一个色综合av| 亚洲婷婷综合久久一本伊一区| 日韩精品在线网站| 欧美日韩国产系列| 99久久伊人精品| 国产一区亚洲一区| 免费观看日韩av| 亚洲综合久久av| 中文字幕中文字幕中文字幕亚洲无线| 欧美日韩mp4| 欧美日韩中字一区| 日本精品免费观看高清观看| 丁香婷婷综合激情五月色| 蜜臀av一区二区| 蜜臀精品久久久久久蜜臀| 日韩精品91亚洲二区在线观看| 亚洲欧美激情视频在线观看一区二区三区| 欧美成人欧美edvon| 欧美一二三四区在线| 日韩精品一区二区三区四区| 日韩一区二区在线观看视频播放| 欧美网站大全在线观看| 欧美日韩中文字幕一区| 欧美日韩视频第一区| 欧美日韩高清一区二区三区| 精品视频在线免费看| 欧美日韩高清一区二区三区| 6080yy午夜一二三区久久| 欧美一级一区二区| www国产精品av| 亚洲欧美日韩国产综合| 亚洲一区二区中文在线| 久久精品99国产国产精| 国产成人综合在线播放| 99久久免费精品| 精品国产欧美一区二区| 中文字幕av一区二区三区| 亚洲成av人片在www色猫咪| 美女脱光内衣内裤视频久久网站| 国产夫妻精品视频| 欧美中文字幕一区二区三区 | 亚洲人成7777| 久热成人在线视频| 色婷婷久久久久swag精品 | 国产日韩欧美精品电影三级在线 | 中文在线资源观看网站视频免费不卡 | 国产福利91精品一区| 欧美在线综合视频| 久久久www成人免费毛片麻豆 | 亚洲欧美韩国综合色| 久久66热偷产精品| 欧美日韩国产一二三| 亚洲免费观看高清| 成人黄色在线视频| 精品日韩在线观看| 日本伊人午夜精品| 91国产丝袜在线播放| 午夜视频在线观看一区二区| av男人天堂一区| 久久精品一区四区| 国产剧情一区二区| 久久精品视频网| 国产一区二区在线免费观看| 日韩精品专区在线影院重磅| 无码av免费一区二区三区试看| 91亚洲精品久久久蜜桃网站| 国产精品久久午夜| www.久久精品| 一区二区三区四区蜜桃| 色综合色综合色综合| 一区二区三区在线观看视频| av电影一区二区| 一区二区三区在线看| 欧美日韩一区二区三区高清| 亚洲h在线观看| 日韩欧美黄色影院| 麻豆精品视频在线观看视频| 精品国产1区二区| 国产91精品欧美| 亚洲私人影院在线观看| 欧洲精品中文字幕| 日韩电影免费一区| 久久夜色精品国产欧美乱极品| 国产成人欧美日韩在线电影| 中文字幕在线观看一区| 欧美亚洲综合一区| 久久99精品国产麻豆不卡| 国产精品少妇自拍| 欧美日韩小视频| 成人一区在线观看| 日本不卡的三区四区五区| 亚洲国产精品99久久久久久久久 | 日本成人中文字幕在线视频 | 欧美一级片在线| av不卡免费电影| 欧美性色综合网| 国产成a人无v码亚洲福利| 香蕉乱码成人久久天堂爱免费| 国产丝袜欧美中文另类| 欧美日韩一区成人| 91在线码无精品| 国产成人高清在线| 久久精品国产**网站演员| 亚洲国产一区在线观看| 国产精品美女www爽爽爽| 日韩亚洲欧美在线| 欧美性受xxxx| 色呦呦国产精品| 成人小视频在线观看| 国产真实乱偷精品视频免| 美女视频黄久久| 久久国产精品区| 日韩av一区二区三区| 午夜电影网亚洲视频| 一区二区三区美女视频| 国产精品国产三级国产普通话蜜臀| 2020国产精品自拍| 亚洲国产精品传媒在线观看| 欧美极品aⅴ影院| 国产精品福利一区二区三区| 国产精品婷婷午夜在线观看| 久久精品综合网| 国产精品美女久久久久av爽李琼| 亚洲国产激情av| 亚洲三级在线播放| 五月天国产精品| 精品一区二区免费| 成人的网站免费观看| 91亚洲精品久久久蜜桃网站| 欧美色偷偷大香| 日韩三级视频在线看| 国产欧美日韩另类一区| 国产精品电影一区二区| 亚洲一区二区在线观看视频| 蜜乳av一区二区三区| 国产精品996| 欧美在线你懂得| 久久众筹精品私拍模特| 自拍偷拍亚洲欧美日韩| 美洲天堂一区二卡三卡四卡视频 | 精品国产区一区| 亚洲最色的网站| 国产九色精品成人porny| 欧美色视频在线观看| 中文字幕一区视频| 国产一区二区美女| 91精品国产91热久久久做人人| 国产精品毛片高清在线完整版| 日韩精品三区四区| 一本一道久久a久久精品| 久久久久久一二三区| 五月婷婷综合网| 91丝袜美腿高跟国产极品老师 | 国产亚洲一区二区三区在线观看| 亚洲一区二区综合| 91视视频在线直接观看在线看网页在线看| 欧美理论电影在线| 亚洲最大成人网4388xx| 不卡一卡二卡三乱码免费网站| 精品电影一区二区三区 | 狠狠色丁香久久婷婷综合_中 | 91精品国产美女浴室洗澡无遮挡| 亚洲人成7777| 色综合天天性综合| 亚洲日本中文字幕区| 99精品桃花视频在线观看| 国产精品人妖ts系列视频| 国产电影一区二区三区| 中文字幕乱码亚洲精品一区| 国产成人av电影在线| 亚洲免费av观看| 欧美一区二区私人影院日本|