Page MenuHomeFeedback Tracker

Make available to override any object Cast
New, UrgentPublic

Description

Example : we try Cast item optic from some class, and if this class has overridden itemoptic Cast he could return child or something.Why it needed? Because some function in some class cannot by overred and class maybe has more functions in engine, like as GetAttachedOptics. It will be useful for implement new features without serious refactoring vanilla classes.

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 10
Category
General

Event Timeline

Mortan created this task.Nov 8 2021, 6:54 PM

Hello @Mortan,

can you please provide code examples for what you describe? Unfortunately, I do not understand what you are trying to suggest.

Mortan added a comment.Nov 8 2021, 7:59 PM
class SomeClass
{
	private ItemOptic m_optic;
	
	operator ItemOptic()
	{
	    return m_optic;
	}
};

//And use : 
SomeClass someclass_obj = ...etc;
ItemOptic optic = ItemOptic.Cast(someclass_obj); // optic == m_optic;

Casting to a different base class is not possible by design. ItemOptic and "SomeClass" must have a common base class. e.g SomeClass : ItemOptic.
Changed applied to base classes like ItemOptic via the modded keyword will also be visible to a casted instance.

I am not sure why you would want to override a cast operator. Whatever you are trying to do, there should be a clean existing way of doing so.
Feel free to share the use-case that made you want to be able to overload the operator so I can point you in the right direction.

Im trying to implement rail for scopes without craft or any hacks, and i stuck on DayZPlayerCamera & WeaponManager classes because they uses many proto native functions from ItemOptic class. If we can override cast or GetAttachedOptics function I would be happy)