• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object and casting reloaded

 
Jason Attin
Ranch Hand
Posts: 232
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, so seen all the problems I've had with objects and casting, I created my own class and tried a few things. Hopefully it's not an exact repetition of the previous one, be there certainly are some similarities, especially in the hierarchical structure,but I figured that this would help me to understand things a bit better. SO here is the code with comments, let me know what you think:

 
Henry Wong
author
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Attin wrote:SO here is the code with comments, let me know what you think:



Whether this line works or not, will depend on what is happening in the previous lines. You are correct that an A instance is not IS-A B type, but look at your previous code... did you happen to assign something to the "a" reference that happens to be IS-A B?

Henry
 
Henry Wong
author
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Attin wrote:SO here is the code with comments, let me know what you think:



Same as my previous post. Did you happen to assign something to the "a" reference that is IS-A C instance? If so, then the cast will succeed. If not, then the cast will fail, and this is regardless of whether you assign it to some C reference or not.

Henry
 
Jason Attin
Ranch Hand
Posts: 232
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah OK I see, those assignments should be taken on their own, if I comment out then  doesn't work anymore
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic