C++ for VB Programmers
This book teaches C++ as it is used in the Visual C++ programming environment from the perspective of an intermediate to advanced level VB programmer.
1102542712
C++ for VB Programmers
This book teaches C++ as it is used in the Visual C++ programming environment from the perspective of an intermediate to advanced level VB programmer.
54.99 In Stock
C++ for VB Programmers

C++ for VB Programmers

by Jonathan Morrison
C++ for VB Programmers

C++ for VB Programmers

by Jonathan Morrison

Paperback(1st ed.)

$54.99 
  • SHIP THIS ITEM
    In stock. Ships in 1-2 days.
  • PICK UP IN STORE

    Your local store may have stock of this item.

Related collections and offers


Overview

This book teaches C++ as it is used in the Visual C++ programming environment from the perspective of an intermediate to advanced level VB programmer.

Product Details

ISBN-13: 9781893115767
Publisher: Apress
Publication date: 09/21/2000
Edition description: 1st ed.
Pages: 408
Product dimensions: 7.52(w) x 9.25(h) x 0.04(d)

About the Author

Jonathan Morrison has written several books on C++ and Visual Basic programming, and has over seven years of experience developing applications in Visual Basic, C++, and Java. He has consulted for Racal Datacom, The Maxim Group, and Cyberguard, and has held lead development positions at AIG, Autonation USA, and Digitalbond Inc. He currently works for Microsoft's Solution Integration Engineering Team, where he helps Microsoft's enterprise customers design, develop, and debug their large-scale applications.

Read an Excerpt

Chapter 4: C++ 101

Well, it's inevitable. If we are going to do anything useful with C++ we are going to have to learn the syntax of the language. Because you already know Visual Basic, it seems logical to use this knowledge as a crutch for learning C++, which is what we will do throughout this chapter.

As you start to learn C++ it is important to remember that you already know how to program—you just don't know the syntax of C++. Think of the process as learning how to drive a new type of car for the first time. You already know how to drive; you just have to learn where the trunk release is and how to set the clock in the new car and you're as good as you were in your old car.

Data and Variables

Regardless of the language in which it was written, every computer program contains some amount of data. Even if the program is only to write the words "Hello World," the fact that a program runs on a computer is proof that the program contains data. Thus, it is a good idea to start our learning of the C++ language by examining the available C++ data types, their Visual Basic equivalents (where appli-cable), and their storage capacity, which is summarized in Table 4-1. You can see that there are many different data types available in C++. Also notice that in most cases they map directly to Visual Basic types.

NOTE: The void data type in C++ is special in that it has no value. It is used to show that there is an absence of value. The void type is usually used as the return type of a function to denote that the function does not return a value, or as the only item in a parameter list for a function that takes no arguments.

Declaring Variables

Knowing the data types available in C++ is one thing, but we also need to know how to declare variables in order to make use of these data types. The syntax for variable declaration is in the form:

DataType VariableName [=InitialValue ];

An example declaration is as follows:

int x =0;

This statement assigns the value 0 to the variable x . In fact, any of the numeric data types in C++ (which include short, int, long, float and double) can be initialized in this way. Now you may have noticed that the keyword unsigned appears before some of the types in our data type chart. This is because C++ supports the idea of unsigned numbers. An unsigned number is simply a number whose value cannot be less than zero. Unsigned numbers are useful for several applications, such as representing binary data. (In contrast, Visual Basic has only one unsigned data type, Byte, which covers the range 0 to 255.) For example, if I wanted to assign the number 14 to x in my code, I would write the following assignment statement:

unsigned int x =14;

The numeric data types are straight forward, but there are several data types that require a little more explanation as to how they are used. We'll look at those now.

NOTE: unsigned can prefix most C++ numeric data types.
The char Data Type
The char data type is quite flexible. It can be used for its namesake and hold a single character with an assignment such as the following:

char myChar ='a';

Notice the use of single quotes surrounding the initializing value of a . When you want to assign a single character to a variable of type char, you must always surround it with single quotes. You may assume that because we told our program to store the character a in memory that it did. Well, actually it didn't. Don't assume that we have a renegade variable here; it is just that a computer is not able to store characters—only numbers.

So what does get stored as the value of myChar? The number 61, which just happens to be the hexadecimal equivalent of the number 97, which just happens to be the ASCII (American Standard Code for Information Interchange) value for the character a.

Make sense? Good. Now don't let this confuse you. The key thing to remember is that all of the data in a computer is stored as numbers. It is the context in which we use those numbers that generates meaning. Think of the saying, "One man's trash is another man's treasure." To someone just looking at the memory stored in our program, the number 61 doesn't mean anything. But, because we know that 61 is the ASCII representation of a character, to us it means a lot. Just remember that all data interpretation is relative to its intended use. (This concept will start to make more sense when we cover the printf()function later in this chapter.)

The char [] Data Type
The char[] data type is not a unique data type; it is just an array of char, or basically a string of characters. We could use this data type to store any character string that is too large for the type char. (In other words, a string that is more than one character long.) Following is an example usage of type char[]...

Table of Contents

1 Why C++? (And Why with Visual Basic).- 2 Where Do We Start?.- 3 How Do You Do That Voodoo That You Do?.- 4 C++ 101.- 5 It’s Not Polite to Point.- 6 Classes.- 7 Templates.- 8 Putting It All Together.- 9 What’s the DLL, Man?.- 10 Your First Real DLL.- 11 An ATL Primer.- 12 The COM Project.- 13 Advanced Topics.- Appendix A A Thread to Visual Basic.- Just Because You Can, Doesn’t Always Mean that You Should.- A Quick Review of Multithreading.- The Threading Contract.- The CreateThread API.- The CreateThread API Revisited.- Conclusion.- Appendix B Visual Basic Strings: The BSTR Data Type.- What Is a BSTR?.- Using_bstr_t.- Conclusion.- Appendix C Article 3. Strings the OLE Way.- Unicode Versus ANSI.- What Is a BSTR?.- The String Class.
From the B&N Reads Blog

Customer Reviews