Jerry Feldman wrote:
On Sun, 04 May 2008 01:26:42 -0400 Sam Clemens
wrote: I'm finally getting around to learning C++ (solely because I believe that C++ + Qt is the best development environment for turning a series of rather complex boards game into a computer game).
The last time I did any serious programming (other than writing shell scripts), ANSI C was still brand new. The K&R C book was still the standard reference & textbook.
There are a lot of good books on C++. (I started with the original K&R C pre-ANSI which I still have). The problem with C++ and other OO languages, is when you are coming from a procedural language like C, you tend to write C programs in C++. To properly program in C++ (or in Java for that matter), get a book on C++ style in addition to a good C++ reference. There is also a C++ GUI programming with QT3. Also, you'll find that there are some rules in C++ that differ from C. For instance, in C a function declaration: int foo(); is legal for: int foo(int arg1, int arg2, ..., int argn)
I have a couple. O'Reily's C++ book, the latest edition of Strastroup's latest book, and one from Dietel, Dietel and Associates (pretty good other than the annoying and childish cartoons of anthropomorphized bees --which have faces that are just plain...creepy looking -- like when they're out of public view, theyre involved in some sort of felonious conduct).
{ ... } Where the elipses in this example are intended just to show arguments, not varargs.
This is legal in standard C for backwards compatibility with K&R.
In C++, this is illegal. C++ requires full prototypes. A declaration like "int foo();" in C++ means zero arguments. Additionally, "int foo(void)" is not in the C++ standard, and may be rejected by the compiler, though I've seen g++ and other compilers accept it.
Yeah, I came across that with an older C++ book I read several years ago (at the time I purchased it in the early 1990's, I didn't have a computer of my own to learn on).
Additionally, a C struct in C++ is a class with all members being public, and has a default constructor and destructor.
That parallel is pretty obvious.
C++ standard header files do not use the .h:
Got caught with that one a couple times.
Additionally, the standard C header files are included in C++ as in this example:
#include <iostream> // The C++ iostream header #include <cstdio> // The C stdio. int main() { std::cout << "Hello, world:-)\n" printf("Hello, world:-)\n"); return 0; }
You really should not mix C and C++ I/O in the same module, but there are many cases where it may be necessary. Remember that the main() function ALWAYS returns an int, never "void".
In actuality, even with C, main() always returns an int. Otherwise, shell scripts looking for a return value would break. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org