inheritance

Why is this invalid Scala?

我只是一个虾纸丫 提交于 2021-02-11 06:46:18
问题 I'm working with abstract types, and I'm wondering why this is invalid: class A {} class B extends A {} class X {type T = A} class Y extends X {override type T = B} Seeing as B <: A, why can't I assign B to T? I get this error: overriding type T in class X, which equals A; type T has incompatible type class Y extends X {override type T = B} Any help would be appreciated. 回答1: When you say this: class X {type T = A} you say: T is exactly A or T is an alias for A . It can't be anything else,

Why is this invalid Scala?

本秂侑毒 提交于 2021-02-11 06:46:17
问题 I'm working with abstract types, and I'm wondering why this is invalid: class A {} class B extends A {} class X {type T = A} class Y extends X {override type T = B} Seeing as B <: A, why can't I assign B to T? I get this error: overriding type T in class X, which equals A; type T has incompatible type class Y extends X {override type T = B} Any help would be appreciated. 回答1: When you say this: class X {type T = A} you say: T is exactly A or T is an alias for A . It can't be anything else,

best way to inherit from a class without virtual functions

馋奶兔 提交于 2021-02-11 04:59:00
问题 I am trying to implement some event handling. There are different types of events: integerChangedEvent, boolChangedEvent, stringChangedEvent and so on... Each of these events hold some of the same information like: std::string settingsName, std::string containerName... But also each of these different event types also hold some information which are unique for this event types: e.g. int double std::string... newValue and oldValue. My idea to not copy the same code thousands of times is to

C++ virtual method not called as expected

点点圈 提交于 2021-02-11 04:29:03
问题 I'm fiddling around with proper overriding of virtual methods. I chain some constructors and in the base class constructor I call a virtual method. Call chain should be as followed: B(p)->A(p)->B.foo(p) Call chain is in C++: B(p)->A(p)->A.foo(p) Call chain is in C#: B(p)->A(p)->B.foo(p) So in other words, in C# behaviour is like expected, in C++ it isn't. C++ Code: #include <cstdio> class A { public: A(); A(int); virtual void foo(int s); }; class B : public A { public: B(); B(int s) : A(s) {}

C++ virtual method not called as expected

感情迁移 提交于 2021-02-11 04:22:26
问题 I'm fiddling around with proper overriding of virtual methods. I chain some constructors and in the base class constructor I call a virtual method. Call chain should be as followed: B(p)->A(p)->B.foo(p) Call chain is in C++: B(p)->A(p)->A.foo(p) Call chain is in C#: B(p)->A(p)->B.foo(p) So in other words, in C# behaviour is like expected, in C++ it isn't. C++ Code: #include <cstdio> class A { public: A(); A(int); virtual void foo(int s); }; class B : public A { public: B(); B(int s) : A(s) {}

C++ virtual method not called as expected

谁说胖子不能爱 提交于 2021-02-11 04:22:23
问题 I'm fiddling around with proper overriding of virtual methods. I chain some constructors and in the base class constructor I call a virtual method. Call chain should be as followed: B(p)->A(p)->B.foo(p) Call chain is in C++: B(p)->A(p)->A.foo(p) Call chain is in C#: B(p)->A(p)->B.foo(p) So in other words, in C# behaviour is like expected, in C++ it isn't. C++ Code: #include <cstdio> class A { public: A(); A(int); virtual void foo(int s); }; class B : public A { public: B(); B(int s) : A(s) {}

C++ virtual method not called as expected

拜拜、爱过 提交于 2021-02-11 04:21:17
问题 I'm fiddling around with proper overriding of virtual methods. I chain some constructors and in the base class constructor I call a virtual method. Call chain should be as followed: B(p)->A(p)->B.foo(p) Call chain is in C++: B(p)->A(p)->A.foo(p) Call chain is in C#: B(p)->A(p)->B.foo(p) So in other words, in C# behaviour is like expected, in C++ it isn't. C++ Code: #include <cstdio> class A { public: A(); A(int); virtual void foo(int s); }; class B : public A { public: B(); B(int s) : A(s) {}

Web API change JSON parser

独自空忆成欢 提交于 2021-02-11 00:12:03
问题 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

Web API change JSON parser

て烟熏妆下的殇ゞ 提交于 2021-02-11 00:10:37
问题 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

Web API change JSON parser

人盡茶涼 提交于 2021-02-11 00:09:54
问题 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