BORLAND Bar/Ana C++ Version 2.0
Total Page:16
File Type:pdf, Size:1020Kb
2.0 BORLAND Bar/ana C++ Version 2.0 Getting Started BORLAND INTERNATIONAL, INC. 1800 GREEN HILLS ROAD P.O. BOX 660001, SCOTTS VALLEY, CA 95067-0001 Copyright © 1991 by Borland International. All rights reserved. All Borland products are trademarks or registered trademarks of Borland International, Inc. Other brand and product names are trademarks or registered trademarks of their respective holders. Windows, as used in this manual, refers to Microsoft's implementation of a windows system. PRINTED IN THE USA. Rl 10987654 c o N T E N T s Introduction 1 Built-in assembly language What's in Borland c++ . .. 1 programming ..................... 22 Hardware and software requirements ... 3 VROOMM (overlays) . .. 23 Writing for Windows . .. 3 Borland's Programmer's Platform The Borland c++ implementation ....... 3 (IDE) ............................. 23 The Borland c++ package .............. 4 Using the manuals ................... 23 Getting Started ...................... 4 Programmers learning C or C++ ..... 24 The User's Guide . .. 5 Experienced C and C++ programmers . 24 The Programmer's Guide .............. 5 Chapter 3 For Microsoft C users 25 The Library Reference . .. 6 Environment and tools ............... 25 The Whitewater Resource Toolkit . ....... 7 The IDE and Windows ............. 26 Typefaces and icons used in these books . 7 Paths for.h and .LIB files ............ 26 How to contact Borland . .. 8 MAKE ............................ 28 Chapter 1 Installing Borland C++ 11 Command-line compiler ............ 32 Using INSTALL ..................... 12 Compatibility command-line options and Laptop systems .................... 13 libraries .......................... 37 The README file . .. 13 Linker ............................ 37 The HELPME!.DOC file ............... 14 Source-level compatibility ............. 39 Turbo Calc . .. 14 __MSC ........................... 39 Customizing the IDE ................. 14 Header files ....................... 39 Running BCINST .................. 15 Memory models ................... 40 Using an EGA card with a CGA Keywords. .. 40 monitor ......................... 15 Intrinsic functions . .. 41 The BCINST Installation menu. .. 15 Register conventions ............... 41 Some specifics ..................... 17 Floating-point return values ......... 41 Segment names . .. 17 Structures returned by value ........ 42 The Debugger menu. .. 17 Chapter 4 A C++ primer 43 Editor commands ................ 18 Encapsulation ....................... 45 Setting your video mode ............ 18 Inheritance .......................... 48 Chapter 2 Navigating the Borland C++ Polymorphism ...................... 50 manuals 21 Overloading ........................ 50 Features ............................ 21 Modeling the real world with classes ... 51 Windows ......................... 21 Building classes: a graphics example .. 51 C++ ............................... 22 Declaring objects . .. 53 Real and protected modes . .. 22 Member functions ................. 53 Calling a member function .......... 54 The C++ streams libraries .......... 106 Constructors and destructors ........ 55 Standard I/O . .. 107 Code and data together ............. 58 Formatted output ... .. 109 Member access control: private, public, Manipulators ................. 110 and protected ..................... 58 put, write, and get ............ 110 The class: private by default ......... 59 Disk I/O ....................... 111 Running a C++ program .. .. 60 I/O for user-defined data types ....... 114 Inheritance . .. 63 Where to now? ..................... 115 Rethinking the Point class ........... 63 Conclusion. .. 116 Inheritance and access control ..... 65 Chapter 5 Hands-on C++ Packaging classes into modules ......' 66 117 Extending classes .................. 70 A better C: Making the transition from Multiple inheritance . .. 73 C ................................. 118 Virtual functions . .. 78 Program 1 ....................... 118 Virtual functions in action . .. 80 Program 2 ....................... 119 Defining virtual functions .. .. 81 Program 3 ....................... 119 Developing a complete graphics Program 4 ....................... 120 module ........................... 82 Object support ...................... 121 Reference types . .. 83 Program 5 ....................... 122 Ordinary or virtual member Program 6 ......................... 124 functions? ......................... 90 Program 7 ....................... 127 Dynamic objects ..................... 90 Program 8 ....................... 128 Destructors and delete . .. 92 Program 9 ....................... 130 An example of dynamic object Summary .......................... 133 allocation ......................... 92 Bibliography 135 More flexibility in C++ ................ 97 Beginning to intermediate ............ 135 Inline functions outside class Advanced .......................... 136 definitions ........................ 97 Object-oriented programming in Functions with default arguments . .. 98 general ............................ 137 More about overloading functions . .. 99 Other languages and C .............. 138 Overloading operators to provide new Programming Windows applications .. 138 meanings ........................ 102 Reference .......................... 138 Friend functions .................. 105 Index 141 T A B L E s 3.1: MAKE and NMAKE options 3.3: CL and BCC options compared ...... 33 compared ........................ 29 3.4: LINK and TLINK options compared .38 3.2: MAKE and NMAKE predefined macros 4.1: Class access ....................... 65 and directives ..................... 31 iii F G u R E s 4.1: C versus C++ ..................... 48 4.3: Multiple inheritance ............... 74 4.2: A partial taxonomy chart of insects .. 49 4.4: Circles with messages .............. 78 iv N T R o D u c T o N Borland C++ is for professional C++ and C developers who want a powerful, fast, and efficient compiler with which to create just about any application, including Microsoft Windows applications. Also with Borland C++, you get both AT&T's C++ version 2.0 and ANSIC. Borland C++ is highly C++ is an object-oriented programming (OOP) language. It's the compatible with existing next step in the natural evolution of C. It is portable, so you can Turbo C code. easily transfer application programs written in C++ from one system to another. You can use C++ for almost any programming task, anywhere. What's in Borland C++ Chapter 1 tells you how to Borland C++ includes many of the latest features users ask for: install Borland C++. Chapter 2 tells you where you can • C++: Borland C++ offers you the full power of C++ program find out more about each of ming (implementing C++ version 2.0 from AT&T). To help you these features. get started, we're also including C++ class libraries. We've also included support for C++ version 1.2 streams. • ANSI C: Borland C++ provides you with an up-to-date imple mentation of the latest ANSI C standard. New! • Microsoft Windows targeting: You can use Borland C++ to write applications for Windows. Many features have been added to support this capability, including the Resource Compiler and the Whitewater Resource Toolkit. We've included a few sample C and C++ Windows applications to help get you going. New! • Precompiled headers, which speed up program compilation time. New! • Real and protected-mode versions of each compiler. You get four compilers with this product: a real and protected-mode Introduction version of the Programmer's Platform, and a real and protected-mode version of the command-line compiler. Each compiler contains both C and C++ capabilities. Running the compiler in protected mode gives you greater capacity with no swapping. _ A container class library giving you bags, sets, arrays, and so on. _ The Programmer's Platform, Borland's next generation of user interface. The Programmer's Platform, also known as the IDE, provides access to the full range of programs and tools on your computer. Running either in protected or real mode, it includes: • a multi-file editor • multiple overlapping windows • mouse support • an integrated debugger New! • a built-in assembler New! • an undo and redo feature with an extensive buffer • support for inline assembler code and much more. _ VROOMM (Virtual Run-time Object-Oriented Memory Manager): VROOMM lets you overlay your code without complexity. You select the code segments for overlaying; VROOMM takes care of the rest, doing the work needed to fit your code into 640K. _ Online hypertext help, with copy-and-paste program examples for practically every function. New! _ The help now includes the Windows API. _ Many indispensable library functions, including heap checking functions and a complete set of complex and BCD math functions. Other features include: New! _ Fast huge arithmetic. _ Far objects and huge arrays. _ Alternate .CFG files. You can create several and use the one that suits your needs at any given time. _ Response files for the command-line compiler. 2 Borland C++ Getting Started Hardware and software requirements Borland C++ runs on the IBM PC family of computers, including the XT, AT, and PS/2, along with all true IBM compatibles. Borland C++ requires DOS 2.0 or higher, a hard disk, a floppy drive, and at least 640K; it runs on any 80-column monitor. Borland C++ includes floating-point routines that let your pro grams make use of an 80x87 math coprocessor chip. It emulates the chip if it is not available. Though it is not required to run Borland C++, the 80x87 chip can significantly enhance