Answer the question
In order to leave comments, you need to log in
What is the difference between dynamic type checking and static type checking?
It was necessary to translate the link type from one to another. Found 2 options - static_cast and dynamic_cast. The first one says that it is unsafe because types are checked at compile time. Here is the question - why did they separate type checking into dynamic and static?
Answer the question
In order to leave comments, you need to log in
I may not have asked the right question. I would like to know why the compiler cannot check everything at compile time. why else add dynamic checking?
class Object {
public:
virtual ~Object() {}
};
class Weapon : public Object {
public:
virtual ~Weapon() {}
};
class Player : public Object {
public:
virtual ~Player() {}
};
void handleObject(Object* object) {
// What is object? Is it weapon or player?
};
// ....
Object* object = rand() % 100 > 50 ? new Weapon() : new Player();
handleObject(object);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question