+ 1
random question: can you change the data type of a variable?
Like without assigning the value to a new variable of another type?
4 ответов
+ 4
In C++, variable types are fix when you declare them. That doesn't prevent you from using the data as a different type because you're allowed to cast it as anything you want.
+ 1
You can do things like encapsulation for example, where class B inherits drom class A and you assing pointer of A to sometihng of type B. You can laso change thing like char to int or vice versa due to the code that character use. It is hard for me to think about other things that may be useful. You can assign any pointer to any other tbh, but I do not think that this will make you any good tho
+ 1
Alright thanks :)
0
yeah sure