[comp.lang.java.programmer, comp.programming removed]
Thanks everyone for your input. I really appreciate your feedback.
To answer various responses, I'm looking at C++ largely because
the particular jobs I'm looking for happen to require C++, not
because I don't like Java anymore. Also, I'll start working with
C# the day they pry my cold, dead hands away from my Sun UltraSPARC
keyboard.
I actually took a step forward a few months ago to review my C++.
I bought a book called Accelerated C++, and it was quite a
revelation. So much has changed since I last studied C++ back
in 1994. e.g. #include <map> instead of #include <map.h>,
namespaces, the use of templates, the STL, etc.
I am glad I already had a strong background in Java's Collections
classes, or else I would have had a hard time learning about STL's
containers with parameterised types. At the very least, "vector"
and "string" are familiar buddies.
W.r.t to vector, (and other stl containers) look out for C++'s
iterator invalidation rules. Every container operation in the
standard library has rules for when it invalidates iterators,
pointers, and references to its elements. Make sure you know them,
e.g., do not forget that:
vector<int> v(10);
vector<int>::iterator i= v.begin();
v.push_back(1); //push_back invalidates all iterators.
int j= *i; //Bad! Has undefined behavior.
has undefined behavior.
I still don't understand what the hell RTTI does,
You will seldom use RTTI directly. Java has RTTI (in fact it has
easier to use and more powerful RTTI than C++ does) ; how often
did you use it?
In any case, here are some rough equivalents w.r.t RTTI:
C++ virtual function => any non-private, non-static method in Java
In Java, all non-private non-static methods are
polymorphic. In C++, only member functions marked 'virtual'
are polymorphic, whether they are private or not. static
member functions cannot be virtual.
Note that many C++ types need no virtual functions
whatsoever.
virtual functions are not precisely RTTI, but they do make
indirect use of the same mechanism, and in C++, only types
that have virtual functions support RTTI.
The FAQ covers virtual functions:
http://www.parashift.com/c++-faq-lite/virtual-functions.html
So does Accelerated C++, see ch 13.
C++ dynamic_cast<T&>(u) => Java (T)u , where T is of polymorphic
class type, and u is a reference to a polymorphic object.
However, while Java's dynamicly typed collections require you to
use (T)u frenquently, C++'s stl containers are staticly typed
generics, and do not require use of dynamic_cast<>. You'll
seldom have reason to use dynamic_cast<>
(Some caution is in order here: C++ does have a notation like
(T)u for casts inherited from C, but there is seldom
reason to use it, and it is *very* different from what (T)u
does in Java. )
I don't see dynamic_cast<> in either the C++ FAQ Lite or
Accelerated C++. Perhaps I'm blind, or perhaps that's a
measure of how seldom it's used.
I can't recall Java's equivalent of typeid(), but it hardly
matters; there is seldom reason to use typeid.
what a virtual destructor is,
A destructor is a special member function which destroys an object. If
the base class destructor is virtual, when the object is destroyed
(by using 'delete', for example) the actual destructor called will
be selected at run time, according to the run-time type of the
object being destroyed (like any other virtual function.)
Accelerated C++ covers virtual destructors in 13.2.2 . The C++ FAQ
lite covers them at
http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.5
and how to resolve circular
inheritence
I would like to know what you are calling ' circular inheritence '. This:
struct Foo : Foo
{
};
is ill-formed in C++ .
[snip]