CPP06 1.0
|
Main entry point for the type identification program. [詳解]
関数 | |
Base * | generate (void) |
Randomly creates an instance of A, B, or C. | |
void | identify (Base *p) |
Identifies the actual type of an object via a pointer. | |
void | identify (Base &p) |
Identifies the actual type of an object from a reference. | |
int | main () |
Main function to test the type identification functions. | |
Main entry point for the type identification program.
main.cpp に定義があります。
Base * generate | ( | void | ) |
void identify | ( | Base & | p | ) |
Identifies the actual type of an object from a reference.
This function determines the runtime type of the object p
by attempting to dynamic_cast it to derived types A, B, and C. It uses a series of nested try-catch(...) blocks to handle cast failures without needing to include <typeinfo> to catch a specific std::bad_cast exception.
void identify | ( | Base * | p | ) |