God I hate it! The message board has eaten my code...
after dynamic_cast there should be a "<" followed by a "int" followed by a ">" and then (Answer). I hope that these symbols will appear....
Bjoern
Is (int (Answer)) a valid c++ statement?
Although it''s preferable to use the new C++-style casts in C++, for this example you certainly don''t want to use dynamic_cast.
dynamic_cast is meant for casting pointers to base classes to pointers to derived classes, and it uses RTTI to check the correctness of the cast. In case of an incorrect cast, an exception is thrown.
Here, you''d use static_cast(Answer), instead of the old C-style (int)Answer cast (which is still valid in C++, as others have pointed out), if you were to use the new C++-style casts.
Erik
dynamic_cast is meant for casting pointers to base classes to pointers to derived classes, and it uses RTTI to check the correctness of the cast. In case of an incorrect cast, an exception is thrown.
Here, you''d use static_cast(Answer), instead of the old C-style (int)Answer cast (which is still valid in C++, as others have pointed out), if you were to use the new C++-style casts.
Erik
Ups, yeah - Erik is right. static_cast is the magic word to cast primitive/non class-inherited types.
Sorry for the wrong info!
Bjoern
Sorry for the wrong info!
Bjoern
I just had to say something :
I read in a book that int(Answer) and (int)Answer end-up with the same result, but the int(Answer) syntax tells the compiler to do some extra error checking, so this may be where the error is coming from: extra error checking.
I read in a book that int(Answer) and (int)Answer end-up with the same result, but the int(Answer) syntax tells the compiler to do some extra error checking, so this may be where the error is coming from: extra error checking.
if (static_cast< int >(Answer) == Wheel)
< for <, and & for &
The reason it deletes these characters is because the forum accepts HTML.
Edited by - CobraA1 on 4/27/00 6:57:52 PM
< for <, and & for &
The reason it deletes these characters is because the forum accepts HTML.
Edited by - CobraA1 on 4/27/00 6:57:52 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement