MFC Programmer's SourceBook : Thinking in C++
Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

Pointers in C++

The most important difference between pointers in C and in C++ is that C++ is a more strongly typed language. This stands out where void* is concerned. C doesn’t let you casually assign a pointer of one type to another, but it does allow you to quietly accomplish this through a void*. Thus,

bird* b;
rock* r;
void* v;
v = r;
b = v; 
C++ doesn’t allow this because it leaves a big hole in the type system. The compiler gives you an error message, and if you really want to do it, you must make it explicit, both to the compiler and to the reader, using a cast. (See Chapter 17 for C++’s improved casting syntax.)

Contents | Prev | Next


Go to CodeGuru.com
Contact: webmaster@codeguru.com
© Copyright 1997-1999 CodeGuru