On Sun, 04 May 2008 01:26:42 -0400
Sam Clemens
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)
{
...
}
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.
Additionally, a C struct in C++ is a class with all members being
public, and has a default constructor and destructor.
C++ standard header files do not use the .h:
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".
--
--
Jerry Feldman