No they do not inherit from the same type, but they all have string variables that need to be treated the same way.
Anyway, I got a very "dirty" solution that I do not like much but that will do it for the moment. I made a function that receive the class object and with a switch case return an object of the good type and it works now, but it piss me off that I cant on the fly cast stuff when language like LUA allow such task...
User Profile
Collapse
-
Because I essentially do the same treatment to 3 different class data, so I do not want to have to write 3 times 400 lines of code when only 1 cast need to be changed.Leave a comment:
-
This was just an example. I would not write you the whole thing because it does 400 lines long. But I need to dynamically cast something as a type I receive as parameter. Your thing for constructor is nice, but I need to cast something that already have variables saved into it.
About:
class Mammal
class Dog : Mammal
class Cat : Mammal
Dog myDoberman = new Dog();
Cat myTabby = (Cat)myDoberman ;//...Leave a comment:
-
It doesnt work, else I would not be asking for help. It just doesnt want to compile. It refuse to take a variable Type for a cast.
In my arraylist, like I said, are homemade class.Leave a comment:
-
Dynamic Cast
How can I make this work? ClassType is the type of an homemade class.Code:void Whatever(Type ClassType, ArrayList myArrayList) { ClassType myClass = new ClassType(); myClass = (ClassType)myArrayList[0]; }
No activity results to display
Show More
Leave a comment: