Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

You can't static_cast between references (or pointers) to "unrelated types." While you could static_cast from a CMyObject* to a CObject*, that isn't what you're doing here. Here you're trying to cast a reference to a pointer into a reference to another pointer. And the two pointer types do not have an inheritance relationship.

I like your "good case 2" code--I'd run with that.

For more details on the non-relatedness of your pointer types, see here: static_cast and reference to pointersstatic_cast and reference to pointers

You can't static_cast between references (or pointers) to "unrelated types." While you could static_cast from a CMyObject* to a CObject*, that isn't what you're doing here. Here you're trying to cast a reference to a pointer into a reference to another pointer. And the two pointer types do not have an inheritance relationship.

I like your "good case 2" code--I'd run with that.

For more details on the non-relatedness of your pointer types, see here: static_cast and reference to pointers

You can't static_cast between references (or pointers) to "unrelated types." While you could static_cast from a CMyObject* to a CObject*, that isn't what you're doing here. Here you're trying to cast a reference to a pointer into a reference to another pointer. And the two pointer types do not have an inheritance relationship.

I like your "good case 2" code--I'd run with that.

For more details on the non-relatedness of your pointer types, see here: static_cast and reference to pointers

Source Link
John Zwinck
  • 252.2k
  • 44
  • 346
  • 459

You can't static_cast between references (or pointers) to "unrelated types." While you could static_cast from a CMyObject* to a CObject*, that isn't what you're doing here. Here you're trying to cast a reference to a pointer into a reference to another pointer. And the two pointer types do not have an inheritance relationship.

I like your "good case 2" code--I'd run with that.

For more details on the non-relatedness of your pointer types, see here: static_cast and reference to pointers