inheritance

Why is is it not possible to pass a const set<Derived*> as const set<Base*> to a function?

隐身守侯 提交于 2020-02-22 12:20:12
问题 Before this is marked as duplicate, I'm aware of this question, but in my case we are talking about const containers. I have 2 classes: class Base { }; class Derived : public Base { }; And a function: void register_objects(const std::set<Base*> &objects) {} I would like to invoke this function as: std::set<Derived*> objs; register_objects(objs); The compiler does not accept this. Why not? The set is not modifiable so there is no risk of non-Derived objects being inserted into it. How can I do

Why is is it not possible to pass a const set<Derived*> as const set<Base*> to a function?

别说谁变了你拦得住时间么 提交于 2020-02-22 12:20:07
问题 Before this is marked as duplicate, I'm aware of this question, but in my case we are talking about const containers. I have 2 classes: class Base { }; class Derived : public Base { }; And a function: void register_objects(const std::set<Base*> &objects) {} I would like to invoke this function as: std::set<Derived*> objs; register_objects(objs); The compiler does not accept this. Why not? The set is not modifiable so there is no risk of non-Derived objects being inserted into it. How can I do

Entity Framework 6 - inheritance and navigation properties on base class

喜欢而已 提交于 2020-02-21 06:30:13
问题 I have a problem with navigation properties and inheritance. This is my problem: I have a base Person class and classes User and Worker which inherit from Person . On the DB level I'm using single table inheritance or table per hierarchy (TPH) inheritance. So there a single table with a discriminator column. Both User and Worker need to have a Company relation, so I would like to define it on the Person class. I define my model like this: [Table("mydb.person")] public abstract partial class

Why aren't fields initialized to non-default values when a method is run from super()?

喜欢而已 提交于 2020-02-19 10:54:34
问题 I must have spent over an hour trying to figure out the reason for some unexpected behavior. I ended up realizing that a field wasn't being set as I'd expect. Before shrugging and moving on, I'd like to understand why this works like this. In running the example below, I'd expect the output to be true, but it's false. Other tests show that I always get whatever that type default value is. public class ClassOne { public ClassOne(){ fireMethod(); } protected void fireMethod(){ } } public class

Why aren't fields initialized to non-default values when a method is run from super()?

▼魔方 西西 提交于 2020-02-19 10:53:26
问题 I must have spent over an hour trying to figure out the reason for some unexpected behavior. I ended up realizing that a field wasn't being set as I'd expect. Before shrugging and moving on, I'd like to understand why this works like this. In running the example below, I'd expect the output to be true, but it's false. Other tests show that I always get whatever that type default value is. public class ClassOne { public ClassOne(){ fireMethod(); } protected void fireMethod(){ } } public class

Why aren't fields initialized to non-default values when a method is run from super()?

佐手、 提交于 2020-02-19 10:53:13
问题 I must have spent over an hour trying to figure out the reason for some unexpected behavior. I ended up realizing that a field wasn't being set as I'd expect. Before shrugging and moving on, I'd like to understand why this works like this. In running the example below, I'd expect the output to be true, but it's false. Other tests show that I always get whatever that type default value is. public class ClassOne { public ClassOne(){ fireMethod(); } protected void fireMethod(){ } } public class

Clone derived class from base class method

醉酒当歌 提交于 2020-02-18 13:39:10
问题 I have an abstract base class Base which has some common properties, and many derived ones which implement different logic but rarely have additional fields. public abstract Base { protected int field1; protected int field2; .... protected Base() { ... } } Sometimes I need to clone the derived class. So my guess was, just make a virtual Clone method in my base class and only override it in derived classes that have additional fields, but of course my Base class wouldn't be abstract anymore

Difference between classical inheritance and prototype inheritance

一个人想着一个人 提交于 2020-02-18 05:16:19
问题 I found this definition here : https://medium.com/javascript-scene/10-interview-questions-every-javascript-developer-should-know-6fa6bdf5ad95#.y0nc8kx34 Doesn't it sound awkward to you ? Does this definition make sense ? For me in both case there is a use of a constructor (with new you can override the returned object that's all) and in both case there is a prototype inheritance. Am I missing something or the definition above is not really accurate ? *3. What is the difference between

Difference between classical inheritance and prototype inheritance

亡梦爱人 提交于 2020-02-18 05:16:05
问题 I found this definition here : https://medium.com/javascript-scene/10-interview-questions-every-javascript-developer-should-know-6fa6bdf5ad95#.y0nc8kx34 Doesn't it sound awkward to you ? Does this definition make sense ? For me in both case there is a use of a constructor (with new you can override the returned object that's all) and in both case there is a prototype inheritance. Am I missing something or the definition above is not really accurate ? *3. What is the difference between

Linker error when using a template class? [duplicate]

你离开我真会死。 提交于 2020-02-15 07:39:46
问题 This question already has answers here : Why can templates only be implemented in the header file? (16 answers) Closed 2 years ago . I'm getting an "unresolved external symbol "public:__thiscall hijo<int>::hijo<int>(void)" referenced in function_main I started a new project cause I was having this same error on another larger project. The error occur when I try to allocate space using the new keyword. If this error is silly please forgive me cause I haven't programmed anything in the last