C++ will normally not allow you to copy a pointer of one type to a pointer of another type. The following generates a compile time error:
float *fp = new float; int *ip = fp; // illegal pointer assignment
However, when using derived classes you may find that you sometimes need a variable of type pointer-to-base-class and other times you need a variable of type pointer-to-derived-class. You may assign the value of a variable of one class to a variable of another class by using a cast.
A cast is an attempt to assure the strongly-typed C++ compiler that you understand what you are pointing at, even though the compiler is not sure. To cast one pointer type to another, simply put the desired type in parentheses before the pointer variable - for example,
F_Node *someNodePtr; erpNode *myErpPtr; ... myErpPtr = someNodePtr; // compiler won't allow this myErpPtr = (erpNode*)someNodePtr; // compiler allows this
Here, the compiler allows the F_Nodestar variable someNodePtr to be assigned to the erpNode* variable myErpPtr only if we cast it first to show the compiler we know we are doing something risky, and we take full responsibility for any disasters that occur.
You may cast the return value of a function also:
F_Node* someFcn(); // forward declaration of function returning F_Node* erpNode *myErpPtr; ... myErpPtr = someFcn(); // compiler won't allow this myErpPtr = (erpNode*)someFcn(); // compiler allows this