A pointer to base class, if assigned to a derived class, only points to the base part right? So you can only use the base part of the derived class with that pointer and no methods from the derived class?
Also one small side question, if in the function definition I do not give my parameter names, only their types, they are in accessible in the function to me right? Cause I cannot call them.
A pointer to base class, if assigned to a derived class, only points to the base part right? So you can only use the base part of the derived class with that pointer and no methods from the derived class?
I assume this is the same for references?
Yup. You can however cast that pointer to a pointer of the derived class type (if the instance pointed to indeed is a valid instance of the derived class), and then you can access the derived class's functions and variables.
Also one small side question, if in the function definition I do not give my parameter names, only their types, they are in accessible in the function to me right? Cause I cannot call them.
Yup too. They are unidentifiable, there is no way to use them.
If you can, get hold of the Design Patterns book by Gamma, Helm, Johnson & Vlissides - it gives a complete picture, while the stuff on the net doesn't. The examples on the net are good for trying to visualise different real world situations where various Design Patterns might be needed.
If not, I am sure you know much more about this than me, could you describe a quick example of what you do with casting & why?
At the moment I am under the impression that casting from one class to another (even if they are related by inheritance) is bad news, along with RTTI. Maybe that is an extreme view? Or is it like a lot things: that are valid / appropriate in some situations, but not in others?
I look forward to your answer, but it maybe a while before I reply - it's 04:45AM at this end, so I am going to stack ZZZZZZZzzzzzz...... :)
At the moment I am under the impression that casting from one class to another (even if they are related by inheritance) is bad news, along with RTTI.
It's expensive (especially dynamic_cast), so it would be bad in speed/time critical situations. I know static_cast<> is faster/less expensive, but don't know how much or if it is recommended in a time sensitive situation either.