polymorphism

Class with generic list of the inherited class type

若如初见. 提交于 2019-12-11 18:03:55
问题 I have 3 class: some of theme have list called descendents of some type. I would like to have a generic class in the BaseHeaderFooterItem class. and insery and type of list to it. Is there any option ? #region ParentItem public class BaseHeaderFooterItem { public string Title { get; set; } public string EnTitle { get; set; } public HyperLink Link { get; set; } public int Level { get; set; } } #endregion #region HeaderFooter public class HeaderFooter : BaseHeaderFooterItem { public List

Class containing container with template objects

穿精又带淫゛_ 提交于 2019-12-11 17:31:02
问题 I have a class class A{ vector<B> arr; }; where template <class T> class B{ T member; }; How want to be able to do something like A container; B<int> b1; B<char> b2; ... container.arr.push_back(b1); container.arr.push_back(b2); I tried adding template before class A, but i do not want to have to specify the template by class A, because then I wont be able to push objects of different types. How am I supposed to deal with this? 回答1: A template is a compile-time code generation construct. In

where to declare the data that needs to be accessible to multiple objects?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 17:13:02
问题 I have just started to work with multiple objects/classes and I am having a hard time figuring out how to implement the data structure properly Assuming I have a base class class control { protected: char* location /* node** adjacency_list; This doesn't work */ }; and two different derived classes class carA:public control { }; class carB:public control { }; and a node class. My problem starts when I try to implement a 2D-ish structure like an array of linear linked list (graph) based on

Polymorphic dummy allocatable argument

廉价感情. 提交于 2019-12-11 17:08:12
问题 I have three functions that to the same thing but for different dummy argument types: flip, flipLogical and flipInt. Their very code is actually exactly the same! There is another function, called flip3D, which is only for real dummy arguments, that calls flip from its inside. This is the way that everything is working right now: function flip(data) real, dimension(:,:), intent(in) :: data real, dimension(:,:), allocatable :: flip integer :: m, n, i m = size(data,1) n = size(data,2) allocate

deserialization from an abstract base fails for boost serialization

≡放荡痞女 提交于 2019-12-11 17:07:29
问题 I'm able to serialize an object through an abstract base using boost::serialization. However, when I try to add deserialization, I get compile errors about the abstract base. Here's my serialization code that works: /* g++ -Iinclude/ -Llib -lboost_serialization ~/Desktop/ser_ex.cpp -o stest */ #include <boost/serialization/serialization.hpp> #include <boost/serialization/nvp.hpp> #include <boost/archive/binary_oarchive.hpp> #include <boost/serialization/vector.hpp> #include <iostream>

Polymorphism with Database Query

混江龙づ霸主 提交于 2019-12-11 17:02:33
问题 I am designing a dashboard to display corporate metrics (currently with ASP.net 3.5 in C#), and looking for advice on design. I'm not as used to OOP in web applications. There may be many different metrics that can be seen by different users in a Many-to-Many relationship. I am storing the users in a local SQL database and it of course makes sense to store the metadata for each "Metric" as well. This also provides a sort of access control list for each one. Each metric can have several

InvalidSchemaException using JsonSubTypes, not picking up what I defined in the base interface

≡放荡痞女 提交于 2019-12-11 15:18:21
问题 The JsonSubTypes that are being picked up are not the ones that I was expecting it to pick up. /* ANIMAL: BASE */ @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({ @Type(value = CatTopic.class, name = "CAT"), @Type(value = DogTopic.class, name = "DOG"), @Type(value = FishTopic.class, name = "FISH"), @Type(value = LamaTopic.class, name = "LAMA") }) public interface AnimalTopicDeclInterface {} and these classes public abstract

Getting “ArgumentError (wrong number of arguments (given 3, expected 2))” when checking user for roles

╄→尐↘猪︶ㄣ 提交于 2019-12-11 15:05:29
问题 I am using the Rolify Gem on a Rails application. This has worked well until today. I was installing webpacker and stimulus and while doing that ran Bundle Update. This appears to have broken my Rolify functionality. Examined User model carefully and compared to another app where Rolify is still working. Checked Role model, checked database schema to ensure users_roles table is intact. Is there anything in a polymorphic relationship that could cause that Argument error? I apologize if this

How to deserialize polymorphic collections in JsonFX?

孤街醉人 提交于 2019-12-11 14:49:23
问题 My JsonFX serialization code works, but the object that I'm serializing contains a list of polymorphic entities, and they're all deserialized as their base type and not their actual type. Here's my serialization code: public static string Serialize(System.Object obj) { StringBuilder builder = new StringBuilder(); using (TextWriter textWriter = new StringWriter(builder)) { JsonWriter writer = new JsonWriter(textWriter); writer.Write(obj); return builder.ToString(); } } public static T

Getting an instance of a subclass from a different class

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 14:14:33
问题 I am writing a game using the slick 2D engine and my own entity engine to work out the details of a 2D side scroller The way my code currently works is like this: Entity class holds entity information. It can have an Ability, something like Animation or sound or movement. All abilities are subclasses of an abstract class called Ability. I have a method in the Entity class where I wish to get an instance of a specific ability, so that I can use its methods: public Ability getAbility(String id)