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

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

?? 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>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩国产天堂| 久久99国产精品久久| 91老司机福利 在线| 综合分类小说区另类春色亚洲小说欧美 | 国产精品大尺度| 成人av综合在线| 一区二区三区在线视频观看| 色综合天天视频在线观看| 一区二区三区国产精华| 91精品久久久久久久久99蜜臂| 日本成人在线不卡视频| 日韩欧美在线影院| 《视频一区视频二区| 97se狠狠狠综合亚洲狠狠| 亚洲一区二区三区国产| 色欧美88888久久久久久影院| 亚洲欧美综合在线精品| 色播五月激情综合网| 午夜影视日本亚洲欧洲精品| 欧美日韩三级在线| 日日夜夜免费精品视频| 日韩精品一区二区三区在线观看| 久久精品国产一区二区三| xf在线a精品一区二区视频网站| 国产乱码精品一区二区三| 亚洲国产电影在线观看| 色综合久久久久久久久| 五月婷婷久久综合| 日韩一区二区免费电影| 国产精品一区在线观看你懂的| 国产精品乱子久久久久| 色婷婷综合久久久久中文一区二区| 亚洲黄色录像片| 69久久夜色精品国产69蝌蚪网| 国产一区二区三区日韩| 国产精品久久二区二区| 欧美日韩大陆一区二区| 久久国产尿小便嘘嘘尿| 国产精品国产三级国产普通话99 | 丝袜诱惑亚洲看片| 久久综合狠狠综合久久激情 | 日韩成人精品视频| 国产精品日日摸夜夜摸av| jlzzjlzz国产精品久久| 日韩精品国产欧美| 久久青草国产手机看片福利盒子 | 欧美在线观看禁18| 亚洲一区二区三区小说| 日韩一本二本av| 风流少妇一区二区| 一区二区三区四区视频精品免费 | 99久久伊人精品| 日韩电影在线一区| 中文字幕一区二区三区四区不卡 | 国产精品小仙女| 亚洲在线视频网站| 久久精子c满五个校花| 在线成人av影院| av一区二区三区在线| 免费欧美日韩国产三级电影| 亚洲欧美一区二区不卡| wwww国产精品欧美| 欧美视频一区在线| 不卡电影免费在线播放一区| 久久国产综合精品| 亚洲成人动漫在线免费观看| 国产精品久久久久久久久晋中 | 婷婷中文字幕一区三区| 国产精品国产三级国产专播品爱网| 欧美一区二区三区免费视频| 91女神在线视频| 国产精品一区二区三区四区| 秋霞午夜av一区二区三区| 成人免费在线视频观看| 久久久久久电影| 欧美成人欧美edvon| 91麻豆精品91久久久久久清纯| 色域天天综合网| 国产福利不卡视频| 另类小说视频一区二区| 青青草伊人久久| 日韩影院在线观看| 亚洲自拍与偷拍| 亚洲精品国产成人久久av盗摄| 中文字幕不卡的av| 欧美激情一区二区三区蜜桃视频 | 色综合天天性综合| 国产91在线|亚洲| 久88久久88久久久| 美女视频免费一区| 日本欧美一区二区三区乱码| 婷婷国产v国产偷v亚洲高清| 亚洲一区二区三区在线| 亚洲成人综合在线| 视频一区二区不卡| 日韩av二区在线播放| 日韩成人免费电影| 麻豆精品一区二区三区| 麻豆精品一区二区av白丝在线| 美女mm1313爽爽久久久蜜臀| 久久国产精品99久久久久久老狼 | 久久久久久免费网| 久久久精品tv| 国产精品每日更新| 亚洲视频在线一区| 国产视频一区不卡| 亚洲日本一区二区| 亚洲国产三级在线| 亚洲丶国产丶欧美一区二区三区| 一区二区三区在线视频免费观看| 亚洲综合一区二区| 日韩福利电影在线| 福利一区福利二区| 国产精品一级片在线观看| 国产麻豆欧美日韩一区| 成人精品国产福利| 欧美日韩三级一区| 日韩精品自拍偷拍| 国产亚洲综合性久久久影院| 亚洲欧洲www| 日本在线不卡视频一二三区| 精油按摩中文字幕久久| 成人性生交大片免费看视频在线| 色综合久久六月婷婷中文字幕| 欧美日韩精品一区二区三区四区 | 亚洲精品免费一二三区| 亚洲成av人影院| 国内精品久久久久影院一蜜桃| 成人蜜臀av电影| 欧美日韩一区精品| 精品国产三级a在线观看| 亚洲欧美自拍偷拍| 日本三级亚洲精品| av在线综合网| 日韩视频免费观看高清完整版| 中文字幕国产精品一区二区| 婷婷丁香久久五月婷婷| 成人免费高清视频| 欧美一卡二卡在线观看| 国产精品久久777777| 免费成人你懂的| 99re这里只有精品首页| 精品视频一区三区九区| 精品国产乱码久久| 亚洲男人的天堂一区二区| 午夜欧美在线一二页| 国产精品一区一区| 色婷婷av一区二区三区软件| 国产婷婷色一区二区三区 | 欧美日韩国产一区| 精品动漫一区二区三区在线观看| 成人黄色综合网站| 亚洲色图在线看| 欧美在线影院一区二区| 免费欧美日韩国产三级电影| 欧美精品一区二区三区四区| 亚洲综合久久av| 97se亚洲国产综合自在线观| 国产片一区二区| 成人亚洲一区二区一| 国产精品不卡一区| 久久精品99国产精品日本| 欧美视频中文字幕| 日一区二区三区| 91视频www| 日韩区在线观看| 日本中文字幕一区二区有限公司| 9久草视频在线视频精品| 国产精品美女久久久久久久久 | 国产精品99久久久久久久vr| 99精品国产视频| 国产欧美视频在线观看| 国产99一区视频免费| 久久久久久99精品| 成人伦理片在线| 91日韩精品一区| 欧美一区二区三区系列电影| 欧美顶级少妇做爰| 秋霞影院一区二区| 亚洲精品在线网站| 在线观看亚洲精品视频| 国产毛片精品视频| 蜜臀av一区二区在线免费观看| 亚洲综合色视频| 精品国产一区二区三区久久久蜜月| 99re热这里只有精品免费视频| 视频一区在线视频| 亚洲国产精品视频| 亚洲欧美日韩国产手机在线| 久久久久久亚洲综合| 日韩一二三四区| 日韩欧美在线一区二区三区| 色综合久久久久综合99| av日韩在线网站| 91蜜桃网址入口| 色婷婷狠狠综合| 欧美伊人久久久久久久久影院| 粉嫩av一区二区三区在线播放| 国产一区二区h| 极品尤物av久久免费看|