inheritance

Web API change JSON parser

不问归期 提交于 2021-02-11 00:09:15
问题 I am trying to change the JSON parser in my web API project. I have followed the following tutorials: https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/custom-formatters?view=aspnetcore-2.2 https://www.youtube.com/watch?v=tNzgXjqqIjI https://weblog.west-wind.com/posts/2012/Mar/09/Using-an-alternate-JSON-Serializer-in-ASPNET-Web-API I now have the following code: public class MyJsonFormatter : MediaTypeFormatter { public MyJsonFormatter() { base.SupportedMediaTypes.Add(new

Base method hiding in C# and Java

萝らか妹 提交于 2021-02-10 22:52:14
问题 I am coming from Java background and currently learning C#. I just had a big surprise regarding (what I perceive as ) a difference in a way that an object accesses methods from base/derived class. Here is what I mean: In Java if I do something like this class InheritanceTesting { public void InheritanceOne() { System.out.println("InheritanceOne"); } } class NewInherit extends InheritanceTesting { public void InheritanceOne() { System.out.println("InheritanceTwo"); } } then run the following:

The type “MyProject.Bike” does not contain a constructor that takes '0' arguments C#

陌路散爱 提交于 2021-02-10 22:18:10
问题 My problem is perhaps pretty simple, but I just started programming in C#. My problem is, as listed above: "The type "MyProject.Bike" does not contain a constructor that takes '0' arguments". I don't understand, because I don't try to make a call to this constructor with empty parentheses, and reading similar questions were all answered with "You have to much/not enough parameters...". I just made this for learning, but I think inheritance is a pretty important concept, so I would like to be

The type “MyProject.Bike” does not contain a constructor that takes '0' arguments C#

拈花ヽ惹草 提交于 2021-02-10 22:16:57
问题 My problem is perhaps pretty simple, but I just started programming in C#. My problem is, as listed above: "The type "MyProject.Bike" does not contain a constructor that takes '0' arguments". I don't understand, because I don't try to make a call to this constructor with empty parentheses, and reading similar questions were all answered with "You have to much/not enough parameters...". I just made this for learning, but I think inheritance is a pretty important concept, so I would like to be

attempt to index local 'def' (a nil value)

杀马特。学长 韩版系。学妹 提交于 2021-02-10 19:59:25
问题 I'm working on a game. At a certain point, I would like to create special GameObject. The special GameObject is called Projectile and is the same as GameObject but has a dx and dy as well as some other functions that only a projectile will have. I am trying to make Projectile extend the GameObject class, but I run into issues when I try to create an instance of Projectile. I've tried different ways of declaring Projectile and shuffling declaration order but can't seem to figure out why I'm

Can multiple base classes have the same virtual method?

与世无争的帅哥 提交于 2021-02-10 18:50:53
问题 class A has a pure virtual method read() class B has an implemented virtual method read() I have a class C that inherits A and B Can this happen? What I'm trying to achieve is that the two base classes A and B complement each other. So C read() method would actually call class B read() class A { virtual int get_data() = 0; void print() { log(get_data()); } } class B { virtual int get_data() { return 4; } } class C : public A, public B { } C my_class; my_class.print(); // should log 4; I'm not

Can multiple base classes have the same virtual method?

。_饼干妹妹 提交于 2021-02-10 18:50:34
问题 class A has a pure virtual method read() class B has an implemented virtual method read() I have a class C that inherits A and B Can this happen? What I'm trying to achieve is that the two base classes A and B complement each other. So C read() method would actually call class B read() class A { virtual int get_data() = 0; void print() { log(get_data()); } } class B { virtual int get_data() { return 4; } } class C : public A, public B { } C my_class; my_class.print(); // should log 4; I'm not

Overriding property in shared project class

最后都变了- 提交于 2021-02-10 14:37:00
问题 Ok team, Quick summary so you understand my question. We have an MVC app (Proj.MVC) that references a shared project (Shared.MVC). The shared project contains Controllers (BaseController & ApiController), Context, and Session Manager as those will be used by other projects. BaseController & ApiController have a reference to SharedContext and SharedSessionManager. However, some project may need to add additional calls to Context and Session Manager. Now my problem is, I can use Interfaces so

How to make a abstract class with default comments on it?

我与影子孤独终老i 提交于 2021-02-10 14:14:43
问题 I have a superclass with an abstract method I want to provide some comments on the method and if any subclasses inherited this method this comments will come along with it. class MySuper { //some comments protected abstract void myAbstractMethod(); } class MyChild extends MySuper { //some comments @Override public void updateLanguage() { } } 回答1: You need to add proper java-doc comments, than that implementing class will get those. This technique is used in various places inside the jdk too -

Static const variable is not constant in child class

久未见 提交于 2021-02-10 09:34:39
问题 I am using Visual Studio 2008 and have two classes Parent and Child. Parent declares some static const variables in the header, which are then defined in the cpp file. When I try to use the defines as cases in a switch statement in a child class I get the error: C2051: case expression not constant . So I've done some testing and the behavior I'm seeing is somewhat inconsistent. // Parent.h class Parent { public: Parent(); ~Parent(void) { } static const unsigned long A = 1; static const