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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch03.htm

?? 24小時精通VC
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD>		<TITLE>Teach Yourself Visual C++&#174; 5 in 24 Hours -- Hour 3 -- Structures, Classes, and the MFC Class Library</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR><FONT COLOR="#000077">Teach Yourself Visual C++&#174; 5 in 24 Hours</FONT></H1></CENTER><CENTER><P><A HREF="../ch02/ch02.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch04/ch04.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><CENTER><H1><FONT COLOR="#000077">- Hour 3 -<BR>Structures, Classes, and the MFC Class Library</FONT></H1></CENTER><P>In the first two hours, you have learned some of the basic concepts behind C++,and you have written some simple programs. In this hour, you will be introduced tosome more advanced Visual C++ programming topics. In particular, you will learn<UL>	<LI>How functions are used to provide small reusable chunks of code<BR>	<BR>		<LI>How structures and classes are used to create source code and data components<BR>	<BR>		<LI>How expressions and statements are used in C++ programs<BR>	<BR>		<LI>How to use the MFC class library to write Windows programs without using ClassWizard</UL><P>You will also build sample programs that illustrate the topics you learn aboutin this hour.<H2><FONT COLOR="#000077"><B>Using Functions</B></FONT></H2><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>function</I> is a groupof computer instructions that performs a well-defined task inside a computer program.</P><P>Functions are one of the primary building blocks of C and C++ applications. Functionsprovide a way to break up a large program into more manageable parts. At the sametime, functions make it possible to perform the same task at various points withinthe program without repeating the code.</P><P>For example, If you buy a wagon, you'll find that it comes with a full set ofassembly instructions and has four identical wheels. Why should the instructionsrepeat the steps to assemble a wheel four times? It is much easier to describe thewheel assembly process once and indicate that you perform the process for each wheel.The wheel assembly instructions are a module (function), within the full set of assemblyinstructions (program), that is executed four times.</P><P>Every C++ program has at least one function; this function is called <TT>main</TT>.The <TT>main</TT> function is called by the operating system when your applicationstarts; when <TT>main</TT> has finished executing, your program has finished.<H3><FONT COLOR="#000077"><B>Declaring Function Prototypes</B></FONT></H3><P>Before you can use a function, you must declare it by supplying a function prototypeto the compiler. To declare a function, you specify the function's name, its returnvalue, and a list of any parameters that are passed to it, as shown here:</P><PRE><FONT COLOR="#0066FF"><TT>int CalculateAge(int nYearBorn);</TT></FONT></PRE><P>This line is a function prototype for the <TT>CalculateAge</TT> function, whichtakes a single integer as a parameter and returns an integer as its result. A functionthat returns no value is declared as returning the <TT>void</TT> type.</P><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>The traditional way to providefunction prototypes is to place them in <I>header</I> files, which are usually namedwith an <TT>.h</TT> extension.</P><P>Header files that are part of the C++ standard library do not use the <TT>.h</TT>extension; two examples of standard header files are <TT>iostream</TT> and <TT>math</TT>.These header files contain all the prototypes and other declarations needed for IOstreams and math functions to be compiled correctly.<H3><FONT COLOR="#000077"><B>Defining Functions</B></FONT></H3><P>A function is defined the same way the <TT>main</TT> function is defined. Allfunction definitions follow the same pattern; it's basically the function prototypewith the function's body added to it. The function definition always consists ofthe following:<UL>	<LI>The function's return value<BR>	<BR>		<LI>The function's name<BR>	<BR>		<LI>The function's parameter list<BR>	<BR>		<LI>The actual function body, enclosed in curly braces</UL><P>Listing 3.1 shows how to use a function to display the Hello World! message. Torun this project, create a new console-mode project named HelloFunc, using the stepsdescribed for the Hello and Hello2 projects in the first two hours.<H4><FONT COLOR="#000077">TYPE: Listing 3.1. The Hello World! program rewritten touse a function.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>#include &lt;iostream&gt;</TT><TT>using namespace std;</TT><TT>// Function prototype</TT><TT>void DisplayAge(int nAge);</TT><TT>int main()</TT><TT>{</TT><TT>    DisplayAge(42);</TT><TT>    return 0;</TT><TT>}</TT><TT>void DisplayAge(int nAge)</TT><TT>{</TT><TT>    cout &lt;&lt; &quot;Hello World! I'm &quot; &lt;&lt; nAge &lt;&lt; &quot; years old.&quot;  endl;</TT><TT>}</TT></FONT></PRE><P>Because the function doesn't return a value to the calling function, the returntype is defined as <TT>void</TT>.<H3><FONT COLOR="#000077"><B>Calling Functions</B></FONT></H3><P>In the C++ language, the act of transferring control to a function is known as<I>calling</I> the function. When a function is called, you supply a function nameand a list of parameters, if any. The following steps take place when a functionis called:<DL>	<DD>1. The compiler makes a note of the location from which the function was called	and makes a copy of the parameter list, if any.<BR>	<BR>	2. Any storage required for the function to execute is temporarily created.<BR>	<BR>	3. The called function starts executing, using copies of the data that was supplied	in the parameter list.<BR>	<BR>	4. After the function has finished executing, control is returned to the calling	function, and memory used by the function is released.</DL><P>These steps are shown in Figure 3.1, which uses the function from Listing 3.1as an example.</P><P><A NAME="01"></A><A HREF="01.htm"><B>Figure 3.1.</B></A><BR><I>Steps involved in calling a function.</I><BLOCKQUOTE>	<P><HR><B> </B><FONT COLOR="#000077"><B>Just a Minute:</B></FONT><B> </B>The requirement	that you declare functions before using them is an extension of the C++ type system.	Because function prototypes are required, the compiler can detect errors such as	incorrect parameters used in a function call. <HR></BLOCKQUOTE><H2><FONT COLOR="#000077"><B>What Are Structures?</B></FONT></H2><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>structure</I> is a datatype that is an aggregate; that is, it contains other data types, which are groupedtogether into a single user-defined type.<BLOCKQUOTE>	<P><HR><B> </B><FONT COLOR="#000077"><B>Just a Minute:</B></FONT><B> </B>Structures are	commonly used when it makes sense to associate two or more data variables. <HR></BLOCKQUOTE><P>An example of a structure is a payroll record, where the number of hours workedand the pay rate are combined in a structure, as shown in Figure 3.2.</P><P><A NAME="02"></A><A HREF="02.htm"><B>Figure 3.2.</B> </A><I><BR>Structures are made up of member variables.</I></P><P>Declaring a structure introduces a new type of variable into your program. Variablesof this new type can be defined just like <TT>int</TT>, <TT>char,</TT> or <TT>float</TT>variables are defined. Listing 3.2 is an example of how a structure is typicallyused.<H4><FONT COLOR="#000077">TYPE: Listing 3.2. Using a structure to calculate a weeklysalary.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>#include &lt;iostream.h&gt;</TT><TT>struct  TIME_REC</TT><TT>{</TT><TT>    double   dHours;</TT><TT>    double   dRate;</TT><TT>};</TT><TT>int main()</TT><TT>{</TT><TT>    TIME_REC    payrollRecord;</TT><TT>    payrollRecord.dHours = 40.0;</TT><TT>    payrollRecord.dRate = 3.75;</TT><TT>    cout &lt;&lt; &quot;This week's payroll information:&quot; &lt;&lt; endl;</TT><TT>    cout &lt;&lt; &quot;Hours worked : &quot; &lt;&lt; payrollRecord.dHours &lt;&lt; endl;</TT><TT>    cout &lt;&lt; &quot;Rate         :$&quot; &lt;&lt; payrollRecord.dRate  &lt;&lt; endl;</TT><TT>    double dSalary = payrollRecord.dRate * payrollRecord.dHours;</TT><TT>    cout &lt;&lt; &quot;Salary       :$&quot; &lt;&lt; dSalary  &lt;&lt; endl;</TT><TT>    return 0;</TT><TT>}</TT></FONT></PRE><H2><FONT COLOR="#000077"><B>What Are Classes?</B></FONT></H2><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>class</I> allows dataand functions to be bundled together and used as if they are a single element. Classestypically model real-world concepts that have both data and some sort of behavior,although this is not a hard and fast rule.</P><P>Classes are similar to structures; in fact, classes really are just structureswith a different name. Classes have one feature that makes them very useful for object-orientedprogramming: Unless a member of a class is specifically declared as <TT>public</TT>,that member is generally not accessible from outside the class. This means that youcan hide the implementation of methods behind the external interface.<BLOCKQUOTE>	<P><HR><B> </B><FONT COLOR="#000077"><B>Just a Minute:</B></FONT><B> </B>Like functions,	classes are an important part of the C++ programming language. In fact, one of the	earliest names for C++ was C with Classes. <HR></BLOCKQUOTE><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>An <I>instance</I> of a class,sometimes called an <I>object</I>, is an occurrence of a class. An instance of oneof your classes can be used or manipulated inside your programs.</P><P>You normally use classes to model objects in your program. Member functions, describedin the next section, are used to control the state of an object, as well as to accessany data contained in it.</P><P>In programs written with MFC, classes are used to model different parts of theapplication, such as the window frame, menus, buttons, and other controls. Memberfunctions are used to handle specific work that needs to be handled by the class.<H3><FONT COLOR="#000077"><B>Classes Versus Instances</B></FONT></H3><P>Classes and instances of classes are not the same things--this can sometimes bea confusing concept if you are new to C++ or object-oriented programming. Think ofa class as the description of an object; an instance of a class is a concrete occurrenceof that class.<H3><FONT COLOR="#000077"><B>Constructors</B></FONT></H3><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>constructor</I>, sometimescalled a &quot;ctor,&quot; is a special member function that is created when an objectof the class is created.</P><P>A constructor always has the same name as the class and never has a return value,not even <TT>void</TT>. The purpose of the constructor is to place a newly createdobject into a known state. Typically, constructors can allocate system resources,clear or set variables, or perform some other type of initialization.<H3><FONT COLOR="#000077"><B>Destructors</B></FONT></H3><P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>destructor</I>, sometimescalled a &quot;dtor,&quot; is a special member function that is called as an objectis destroyed. The destructor is declared as having no return type and is never declaredwith a parameter list. The name of the destructor is the class name prefixed by atilde (~) character.</P><P>It is not necessary to define a destructor unless there are specific tasks thatmust be performed to clean up after an object, such as releasing system resourcesthat might have been allocated.<H2><FONT COLOR="#000077"><B>Using MFC for Windows Programming</B></FONT></H2><P>In the first hour, you created an MFC program using AppWizard. When you use AppWizardto create a project, it might seem that you get a great deal of functionality forfree. However, a great deal of code is generated--even a simple program like HelloMFCresults in a large number of source files.</P><P>MFC doesn't need to be that complicated. In fact, you can write a very simpleMFC program that fits in a single source file and is about one page long.<H3><FONT COLOR="#000077"><B>The HelloWin MFC Example</B></FONT></H3><P>Listing 3.3 is an example of a simple MFC program that displays a Hello Worldmessage in the center of the client window, much like the HelloMFC program you createdin the first hour.<H4><FONT COLOR="#000077">TYPE: Listing 3.3. A simple Windows program written usingC++ and MFC.</FONT></H4><PRE><FONT COLOR="#0066FF"><TT>#include &lt;afxwin.h&gt;</TT><TT>// The CHelloApp class</TT><TT>class CHelloApp : public CWinApp</TT><TT>{</TT><TT>    public:</TT><TT>        BOOL InitInstance();</TT><TT>};</TT><TT>// The CHelloWnd class</TT><TT>class CHelloWnd : public CFrameWnd</TT><TT>{</TT><TT>    public:</TT><TT>        CHelloWnd();</TT><TT>    protected:</TT><TT>        afx_msg void OnPaint();</TT><TT>        DECLARE_MESSAGE_MAP()</TT><TT>};</TT><TT>// InitInstance - Returns TRUE if initialization is successful.</TT><TT>BOOL CHelloApp::InitInstance()</TT><TT>{</TT><TT>    m_pMainWnd = new CHelloWnd;</TT><TT>    if( m_pMainWnd != 0 )</TT><TT>    {</TT><TT>        m_pMainWnd-&gt;ShowWindow( m_nCmdShow );</TT><TT>        m_pMainWnd-&gt;UpdateWindow();</TT><TT>        return TRUE;</TT><TT>    }</TT><TT>    else</TT><TT>        return FALSE;</TT><TT>}</TT><TT>// Create a message map that handles one message - WM_PAINT</TT><TT>BEGIN_MESSAGE_MAP( CHelloWnd, CFrameWnd )</TT><TT>    ON_WM_PAINT()</TT><TT>END_MESSAGE_MAP()</TT><TT>CHelloWnd::CHelloWnd()</TT><TT>{</TT><TT>    Create( NULL, &quot;Hello&quot; );</TT><TT>}</TT><TT>// OnPaint - Handles the WM_PAINT message from Windows.</TT><TT>void CHelloWnd::OnPaint()</TT><TT>{</TT><TT>    CPaintDC    dc(this);</TT><TT>    dc.TextOut(50, 50, &quot;Hello World!&quot;, 12);</TT><TT>}</TT><TT>// Create a single instance of the application.</TT><TT>CHelloApp   theApplication; </TT></FONT></PRE>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产喂奶挤奶一区二区三区| 国产精品一区二区男女羞羞无遮挡| 麻豆中文一区二区| 黄色日韩三级电影| 欧美日韩极品在线观看一区| 国产精品天天看| 国产精华液一区二区三区| 6080国产精品一区二区| 国产精品久久久一本精品| 国产一二精品视频| 精品国产一区二区三区不卡 | 成人免费毛片片v| 欧美成人女星排名| 精品伊人久久久久7777人| 欧美日韩不卡在线| 久久国产人妖系列| 国产欧美视频在线观看| 99综合影院在线| 一区二区三区在线观看网站| 欧美艳星brazzers| 美腿丝袜亚洲一区| 久久久精品人体av艺术| av在线不卡观看免费观看| 亚洲韩国一区二区三区| 精品久久五月天| 成人app在线| 午夜久久电影网| 久久久久久亚洲综合| 91香蕉视频黄| 日本vs亚洲vs韩国一区三区二区 | 一本久道久久综合中文字幕 | 日本韩国精品一区二区在线观看| 亚洲6080在线| 中文字幕一区免费在线观看| 欧美写真视频网站| 黑人精品欧美一区二区蜜桃| 国产精品美女一区二区在线观看| 欧美自拍偷拍一区| 国产精品自拍网站| 亚洲成人免费av| 亚洲人午夜精品天堂一二香蕉| 欧美片在线播放| 99久久婷婷国产综合精品电影| 视频一区二区中文字幕| 国产精品成人午夜| 精品对白一区国产伦| 国产91精品一区二区| 久久久久国产精品厨房| 91精品国产乱码久久蜜臀| 欧美精品乱码久久久久久按摩| 欧美疯狂做受xxxx富婆| 欧美精品在欧美一区二区少妇| 欧美日韩激情一区二区| 制服.丝袜.亚洲.另类.中文| 91视频com| 99久久久精品| 成人av午夜电影| 国产99久久久国产精品潘金| 成人av资源在线| 国产一区91精品张津瑜| 国产91综合一区在线观看| 日韩精品亚洲专区| 美女www一区二区| 天堂成人国产精品一区| 亚洲综合色区另类av| 一区二区三区在线视频观看58| 中文字幕五月欧美| 亚洲欧洲日本在线| 亚洲欧洲日产国码二区| 亚洲精品国产一区二区三区四区在线| 国产精品三级av在线播放| 国产精品国产自产拍高清av王其| 国产精品国模大尺度视频| 亚洲美女视频在线观看| 伊人色综合久久天天| 亚洲激情欧美激情| 中文一区二区在线观看| 国产精品欧美精品| 亚洲一区二区三区四区在线观看 | 亚洲chinese男男1069| 婷婷六月综合网| 国产中文字幕精品| 99天天综合性| 欧美日韩欧美一区二区| 精品电影一区二区| 亚洲欧美偷拍另类a∨色屁股| 亚洲欧美日韩中文播放| 亚洲成人激情综合网| 黄页视频在线91| 91久久国产综合久久| 日韩三级在线免费观看| 久久婷婷一区二区三区| 国产精品人妖ts系列视频| 亚洲综合色自拍一区| 久久国产精品99精品国产| 不卡的电影网站| 欧美大胆一级视频| 亚洲精品视频在线看| 国产在线精品一区二区三区不卡| 91麻豆123| 国产精品毛片久久久久久久| 日韩av一二三| 在线亚洲一区观看| 国产午夜精品一区二区三区四区| 亚洲国产你懂的| 色婷婷综合在线| 综合久久久久综合| 91亚洲国产成人精品一区二三| 国产欧美1区2区3区| 国产精品1024久久| 国产精品女人毛片| 成人综合激情网| 中文字幕五月欧美| 91福利在线观看| 亚洲综合激情网| 国产中文一区二区三区| 欧美一区二区国产| 亚洲大尺度视频在线观看| 一本大道久久a久久精二百| 欧美高清在线视频| 国v精品久久久网| 精品国产3级a| 国产原创一区二区三区| 精品久久人人做人人爽| 久久国内精品视频| 久久久电影一区二区三区| 韩国女主播成人在线| 欧美不卡一区二区| 国产一区二区调教| 中文无字幕一区二区三区| 成人avav在线| 亚洲成人免费看| 欧美一区二区三区在线| 久久国产生活片100| 久久久久久久久久久电影| 国模少妇一区二区三区| 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 色噜噜狠狠色综合中国| 亚洲色图另类专区| 91首页免费视频| 亚洲精品亚洲人成人网| 一本色道**综合亚洲精品蜜桃冫| 一区二区在线观看不卡| 在线欧美日韩国产| 亚洲成a天堂v人片| 日韩手机在线导航| 成人av午夜电影| 亚洲国产日韩在线一区模特| 欧美精品一卡二卡| 午夜免费久久看| 国产日韩三级在线| 在线免费视频一区二区| 日韩高清在线观看| 国产精品久久久久久户外露出| 91黄视频在线| 免费在线一区观看| 2024国产精品| 欧美另类变人与禽xxxxx| 九色porny丨国产精品| 国产精品久久久久永久免费观看| 欧美日韩小视频| 国产麻豆91精品| 亚洲图片欧美综合| 久久在线免费观看| 日韩一区二区在线观看视频播放| 国产高清视频一区| 水蜜桃久久夜色精品一区的特点| 国产精品乱码人人做人人爱| 欧美日韩久久久久久| 国产999精品久久| 亚洲午夜视频在线观看| 自拍偷拍欧美精品| www国产精品av| 666欧美在线视频| 欧美日韩一区二区三区四区| 大陆成人av片| 国产成人午夜高潮毛片| 国产一区二区三区| 日日欢夜夜爽一区| 一区二区免费视频| 亚洲成人免费电影| 亚洲欧美日韩国产手机在线| 中文字幕二三区不卡| 国产网站一区二区| 91精品久久久久久久久99蜜臂| 色老综合老女人久久久| 99久久久久久99| 99热精品国产| 韩国成人精品a∨在线观看| 五月婷婷另类国产| 日本欧美加勒比视频| 天天色图综合网| 麻豆91在线看| 蜜臀av性久久久久av蜜臀妖精 | 99热在这里有精品免费| 国产成人在线观看| av动漫一区二区| 欧美日韩一区久久| 91精品国产aⅴ一区二区| 日韩视频一区在线观看|