Questions tagged [dynamic-cast]

The dynamic_cast conversion allows for safely converting pointers (and references) to classes up, down, and sideways in the inheritance hierarchy.

From cppreference.com:

Safely converts pointers and references to classes up, down, and sideways along the inheritance hierarchy.

dynamic_cast has usage scenarios and limitations. In general terms this amounts to it being valid for casting polymorphic types and it performs run-times checks to ensure that the result is valid for the requested object type.

621 questions
-4
votes
1 answer

GAME ENGINE : dynamic_cast - Object class is not a polymorphic type

First of all im trying to create a games engine with similar architecture to Unity. I have an Object class, a GameObject class which inherits from Object. Within GameObject class i am trying to make a template class that will let you add any…
Rigged
  • 11
  • 1
-4
votes
1 answer

dynamic_cast is failing when casting from base to child class

I have a struct struct foo : public std::map { }; and a child struct; struct bar : public foo { int another_member; } But I can't use bar* b = dynamic_cast(f) where f is a pointer to a foo. Even if I refactor foo to…
P45 Imminent
  • 8,319
  • 4
  • 35
  • 78
-4
votes
1 answer

Why can't I dynamic_cast this object?

void test() { Token test(); Actor* check; check = dynamic_cast(test); } This method gives me the following error and underlines the test in the braces with red. The operand of a pointer dynamic_cast must be a pointer…
user3330027
  • 1
  • 1
  • 2
-4
votes
1 answer

Initialization of a reference versus initialization of an object

I know dynamic casts works on pointers and references. Both of the following work casting downwards der d; base& b = d; der x = dynamic_cast(b); -->A der& y = dynamic_cast(b); -->B x.method(); y.method(); I wanted to know what the…
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158
-4
votes
1 answer

dynamic cast on interface pointer

I need to cast interface pointer dynamically but my interfaces dont have any virtual method, basically i do not control the code of interfaces and i want to user same pointer to use methods from both interfaces, if i cast dynamically then since…
NxC
  • 320
  • 1
  • 2
  • 16
-4
votes
1 answer

Java to C# Learning/Clarity

So I started learning C# on Monday morning, I have spent the past two days watching video after video and now I have a few observations that I want to know if I am thinking about correctly. My past is about ~4 years of college-level Java…
Austin
  • 3,010
  • 23
  • 62
  • 97
1 2 3
41
42