おやすみ
おやすみ
CC#
Created by おやすみ on 4/19/2024 in #help
Any way to inherit base abstract class' constructor?
here's what i've got so far
public class PushZero : Instruction
{
public PushZero(VirtualMachine globalScope, Procedure scope, Traceback traceback) : base(globalScope, scope, traceback) { }
public override void Callback()
{
scope.instructionPointer++;
globalScope.stack.Push(0);
}
}
public class Add : Instruction
{
public Add(VirtualMachine globalScope, Procedure scope, Traceback traceback) : base(globalScope, scope, traceback) { }
public override void Callback()
{
scope.instructionPointer++;
if (!globalScope.stack.TryPeek(out _))
{
throw new CCLRuntimeError("Instruction '+' cannot add to an empty stack.", traceback);
}
}
}
public class PushZero : Instruction
{
public PushZero(VirtualMachine globalScope, Procedure scope, Traceback traceback) : base(globalScope, scope, traceback) { }
public override void Callback()
{
scope.instructionPointer++;
globalScope.stack.Push(0);
}
}
public class Add : Instruction
{
public Add(VirtualMachine globalScope, Procedure scope, Traceback traceback) : base(globalScope, scope, traceback) { }
public override void Callback()
{
scope.instructionPointer++;
if (!globalScope.stack.TryPeek(out _))
{
throw new CCLRuntimeError("Instruction '+' cannot add to an empty stack.", traceback);
}
}
}
(and some Instructions will have their own fields)
20 replies
CC#
Created by おやすみ on 4/19/2024 in #help
Any way to inherit base abstract class' constructor?
thanks for your answer
20 replies
CC#
Created by おやすみ on 4/19/2024 in #help
Any way to inherit base abstract class' constructor?
i just dont like the fact that i have to basically copypaste the thing into each subclass
20 replies
CC#
Created by おやすみ on 4/19/2024 in #help
Any way to inherit base abstract class' constructor?
well, if using base is the only way, then i guess i can only use that long ahh line 😭
20 replies