Cast Question

can do something like this?

Cast < GetClass() >(some Actor);

I know this one not working, I mean using get class or something instead of typing the class (example UWeaponComp ) or put a variable for Cast.

I hope I have been made my point.

Thanks.

No you can’t. Types can not be ambiguous on compilation time, it is unknown that GetClass() would return at the time compiler process the code. compiler needs to know which type to use to compose CPU machine code to know which instructions to use and obviously you can not do this on runtime. Compiler would not even able to figure out if function and variable references are even valid on the rest of the code referencing to that casted variable.

Closesest thing to what you trying to do is auto type, which task compiler to figure which type to use by looking what other types you use or what type functions return, but it does not replace casting:

https://en.cppreference.com/w/cpp/language/auto

But general solution to this is to make base classes with common functions that you want to use or if you can’t relate multiple classes use interfaces:

And then cast to base class or interface and do calls

Yes like said, I think you need to restructure your class hierarchy so that everything where you need this is already inheriting from a common parent class.

Thanks, useful pieces of information.