Home>
I am currently writing code in Unity C#
When calling an abstract method (function with abstract) in a function of an abstract class
It seems that the method is undefined and an error occurs
How do you describe it when I want to abstract only a specific processing part such as the following?
Is there no choice but to force a default by using virtual for the time being?
abstract class BaseShopRegister{
protected abstract uint CalcTax(uint cost);
public void CalcCost(uint cost){
return CalcTax(cost);// error here.
}
}
class ShopRegister_Old :BaseShopRegister{
protected override uint CalcTax(uint cost){
return cost * 1.05f;
}
}
class ShopRegister_New :BaseShopRegister{
protected override uint CalcTax(uint cost){
return cost * 1.10f;
}
}
virtual version.
class BaseShopRegister{
protected virtual uint CalcTax(uint cost){
return cost;// Force default process? .
}
public void CalcCost(uint cost){
return CalcTax(cost);
}
}
-
Answer # 1
Related articles
- c# abstract class, abstract method
- ruby - i want to know the reason for implementing it in a class method or module when solving an exercise
- i want to use exit outside the ruby class to exit the method processing
- javascript - method function difference (how to call, etc)
- what is the description method described in the text in c# code?
- c# - i want to call monobehaviour: start of class b from class a
- how to receive value from another class in c#
- c# - i want to convert a string type to a class and attach it to an object
- i want to create my own validationattribute class in c#
- [unity] [c#] method cannot be passed from eventscript to addtrigger from script
- i have a question about the c# close method not closing
- javascript - i want to share a method between function components in react
- i'm having trouble creating a function for the email service for account confirmation with aspnet identity (c#)
- c# - [wpf] [mvvm] about the parameter acquisition method at the time of screen transition
- c# - usage for tryparse method of enum (enumeration type)
- c# net core31 i would like to use the role function in the web application identity
- c# - unity: how do i get the "object in the scene" class?
- c# - windows forms execute function of parent form from child form
- c# - how to output from another class to crystalreportviewer in form1
Trends
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs
Excuse me. I wasn't sure what the error was.
I was doing something like this using gameObject and it was just null access.
Calling an abstract method in a function of an abstract class can be done without problems! !! !!