The 6.0 release of Visual C++ shows Microsoft's continued focus on Internet technologies and COM, which are key components of the new Windows Distributed interNet Application Architecture (DNA). In addition to supporting these platform initiatives, Visual C++ 6.0 also adds an amazing number of productivity-boosting features such as Edit And Continue, IntelliSense, AutoComplete, and code tips. These features take Visual C++ to a new level. We have tried to make sure that this book keeps you up to speed on the latest technologies being introduced into Visual C++.
(Click on cover image on the left to download the eBook in CHM / Compiled HTML file format)
Book Chapters:
Windows, Visual C++, and Application Framework Fundamentals
The MFC Library View Class
The Document-View Architecture
Active X: COM, Automation, OLE
Database Management
Programming for the Internet
Copyright© 1998 by David J. Kruglinski
C++ Builder 6 eBook
Developer's Guide (PDF)
Object Pascal Guide (PDF)
Quick Start (PDF)
Documents are in Adobe PDF (Portable Document Format). You'll need a PDF reader to view those documents. C++ 101 recommends FoxIt PDF Reader as it's packed with ton of features, small in size, and best of all... it's totally FREE!
Object Pascal Guide (PDF)
Quick Start (PDF)
Documents are in Adobe PDF (Portable Document Format). You'll need a PDF reader to view those documents. C++ 101 recommends FoxIt PDF Reader as it's packed with ton of features, small in size, and best of all... it's totally FREE!
Differences between C and C++
C++ was based on C and retains a great deal of the functionality. C++ does not retain complete source-level compatability with C. There are a few gotchas for C++ programmers trying to write C code, and C programmers trying to compile with a C++ compiler.
The explanation from Bjarne Stroustrup himself is that this isn't type safe. What this means is that you can have a void* that points to anything at all, and if you then assign the address stored in that void* to another pointer of a different type, there isn't any warning at all about it.
Consider the following:
Implicit Assignment from void*
You cannot implicitly assign from a void* to any other type. For instance, the following is perfectly valid in C (in fact, it's arguably the preferable way of doing it in C)int *x = malloc(sizeof(int) * 10);but it won't compile in C++. (Try it yourself!)
The explanation from Bjarne Stroustrup himself is that this isn't type safe. What this means is that you can have a void* that points to anything at all, and if you then assign the address stored in that void* to another pointer of a different type, there isn't any warning at all about it.
Consider the following:
int an_int;When you assign *double_ptr the value 5, it's writing 8 bytes of memory, but the integer variable an_int is only 4 bytes. Forcing a cast from a void pointer makes the programmer pay attention to these things.
void *void_pointer = &an_int;
double *double_ptr = void_pointer;
*double_ptr = 5;
Freeing arrays: new[] and delete[]
In C, there's only one major memory allocation function: malloc. You use it to allocate both single elements and arrays:int *x = malloc( sizeof(int) );and you always release the memory in the same way:
int *x_array = malloc( sizeof(int) * 10 );
free( x );In C++, however, memory allocation for arrays is somewhat different than for single objects; you use the new[] operator, and you must match calls to new[] with calls to delete[] (rather than to delete).
free( x_array );
int *x = new int;The short explanation is that when you have arrays of objects, delete[] with properly call the destructor for each element of the array, whereas delete will not.
int *x_array = new int[10];
delete x;
delete[] x;
You must declare functions before use
Although most good C code will follow this convention, in C++ it is strictly enforced that all functions must be declared before they are used. This code is valid C, but it is not valid C++:#include
int main()
{
foo();
return 0;
}
int foo()
{
printf( "Hello world" );
}
Gotcha for a C++ programmer using C
Structs and Enums
You have to include the struct keyword before the name of the struct type to declare a struct: In C++, you could do thisstruct a_structand have a new instance of a_struct called struct_instance. In C, however, we have to include the struct keyword when declaring struct_instance:
{
int x;
};
a_struct struct_instance;
struct a_struct struct_instance;In fact, a similar situation also holds for declaring enums: in C, you must include the keyword enum; in C++, you don't have to. As a side note, most C programmers get around this issue by using typedefs:
typedef struct struct_nameNow you can declare a struct with
{
/* variables */
} struct_name_t;
struct_name_t struct_name_t_instance;But there is another gotcha for C++ programmers: you must still use the "struct struct_name" syntax to declare a struct member that is a a pointer to the struct.
typedef struct struct_name
{
struct struct_name instance;
struct_name_t instance2; /* invalid! The typedef isn't defined yet */
} struct_name_t;
C++ has a much larger library
C++ has a much larger library than C, and some things may be automatically linked in by C++ when they are not with C. For instance, if you're used to using g++ for math-heavy computations, then it may come as a shock that when you are using gcc to compile C, you need to explicitly include the math library for things like sin or even sqrt:% g++ foo.cc
or
% gcc foo.c -lm
No Boolean Type
C does not provide a native boolean type. You can simulate it using an enum, though:typedef enum {FALSE, TRUE} bool;
main Doesn't Provide return 0 Automatically
In C++, you are free to leave off the statement 'return 0;' at the end of main; it will be provided automatically:int main()but in C, you must manually add it:
{
printf( "Hello, World" );
}
int main()
{
printf( "Hello, World" );
return 0;
}
Subscribe to:
Posts (Atom)