Visual C .NET 2005 Compiler Part III


Visual C++ .NET 2005 Compiler Part III

It is sometimes useful to place function definitions in a separate file from the program. For example, previously the program: grades.cpp was studied. Look at it one more time. Notice that it contains the function: average(). Suppose that this function is useful in other programs. Therefore if this function is placed into a header like: functions.h, the function could be removed from the program grades.cpp and added to the any program by including the header: functions.h as you can see in the grades2.cpp

Let's now consider how this would be handled in the Visual C++ .NET compiler. Create an empty console project called: grades2. In the Solution Explorer, right click on Source Files, and select Add/Add New Item. Next select a C++ program and name it grades2.cpp. When you do these steps, you should see a screen like the following:

image from book

Click on the grades2.cpp file under the Source Files folder in the Solution Explorer and copy the file: grades2.cpp into the window. You should now see something like the following:

image from book

Next right click on the Header Files folder in the Solution Explorer and do a right mouse click Again select Add/Add New Item but this time choose the Header File (.h) option. What you should see would be like the following graphic:

image from book

Name the header: functions.h and click the Add button When you do this, you should see something like the following:

image from book

Click on the functions.h file under the Header Files folder in the Solution Explorer. Copy the file: functions.h into the blank window on the right side. When you do, you should see something like the following:

image from book

Next on the menu bar select Build/Build Solution and then Debug/Start Without Debugging. Notice that the program compiled and executed.

Additional Header Files could be added to a project or additional Source Files. Notice that the names of the program file and the header file are listed above the window where you pasted the files into. If more files are included into the project their names would appear there as well.




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net