polymorphism Questions

6

Solved

Scott said on Effective C++, 3rd Edition, pg. 43 that to make an abstract class, we just need to give it a pure virtual destructor: class AWOV { // AWOV = "Abstract w/o Virtuals" public: virtual ...
Tomi asked 16/10, 2012 at 15:52

7

Solved

I am attempting to work through a tutorial from Programmer Bruce that is supposed to allow the deserialization of polymorphic JSON. The complete list can be found here Programmer Bruce tutorials (G...
Delmadelmar asked 21/5, 2015 at 0:12

2

I am unclear on what is the best way to design a class with static methods that are meant to be overridable. I will try to explain with an example. We have a class Goat with a method can_climb. ...
Handclasp asked 6/6, 2016 at 14:9

3

Solved

I have the following ASP.NET Web Api 2 action with a ternary if return: [HttpDelete] public IHttpActionResult Delete() { bool deleted; // ... return deleted ? this.Ok() : this.NotFound(); } ...
Socorrosocotra asked 7/1, 2015 at 14:48

3

Solved

I am wondering if it is possible to convert a vector of derived class values to a vector of base class values. Specifically I want to be able to pass a vector of base class objects to a function wh...
Tashinatashkent asked 18/4, 2011 at 2:42

12

Solved

In the example below (from my coursepack), we want to give to the Square instance c1 the reference of some other object p1, but only if those 2 are of compatible types. if (p1 instanceof Square) {c...
Sheff asked 15/11, 2010 at 16:12

2

Solved

I have a class Animal and other animals inherit from it (e.q. Sheep, Wolf).I want to check if two objects are the same class and if so, it should create new object of the same class and if they are...
Strictly asked 6/6, 2015 at 12:22

14

Solved

Is there a construct in Java or C# that forces inheriting classes to call the base implementation? You can call super() or base() but is it possible to have it throw a compile-time error if it isn'...
Merengue asked 20/10, 2010 at 21:57

7

Solved

Can anyone explain the actual use of method hiding in C# with a valid example ? If the method is defined using the new keyword in the derived class, then it cannot be overridden. Then it is the sa...
Pentecost asked 28/7, 2009 at 12:41

4

Solved

As expected, this works fine: foo :: Fractional a => a foo = undefined -- datum bar :: Num a => a -> a bar a = undefined -- function baz :: Fractional a => a baz = bar foo -- applicat...

3

Solved

OCaml has several different syntaxes for a polymorphic type annotation : let f : 'a -> 'a = … (* Isn’t this one already polymorphic? (answer: NO) *) let f : 'a. 'a -> 'a = … let f : type a. a...
Guardant asked 11/9, 2021 at 15:50

18

Solved

I was presented with this question in an end of module open book exam today and found myself lost. I was reading Head first Javaand both definitions seemed to be exactly the same. I was just wonder...
Cavalier asked 10/6, 2011 at 15:0

2

Solved

In a project of mine I encountered this problem where the polymorphism seemingly doesn't work. Derived classes don't seem to override the base class, but no errors ocurr either. This is a simplific...
Revolution asked 20/8, 2021 at 18:53

4

Solved

Higher rank types look like great fun. From the Haskell wikibook comes this example: foo :: (forall a. a -> a) -> (Char,Bool) foo f = (f 'c', f True) Now we can evaluate foo id without the...

5

Solved

I have the following structure: abstract class Base { public abstract List<...> Get(); //What should be the generic type? } class SubOne : Base { public override List<SubOne> Get()...
Smothers asked 24/3, 2009 at 1:26

1

Here are a few simple functions: f1 :: () -> () f1 () = () f2 :: a -> a f2 a = a f3 :: a -> (a, a) f3 a = (a, a) f4 :: (a, b) -> a f4 (a, b) = a All of f1, f2, and f3 are able to ac...

1

Consider the type of a function from a's to pairs of b's and c's, a -> (b, c). (I'll use Haskell notation for types and functions, but this isn't a question about Haskell per se.) There are many...
Brunhilda asked 22/7, 2021 at 22:40

3

Solved

I was wondering what is the meaning of a virtual constructor and how would it be used. In addition I know that C++ does not allow for a virtual constructor, and I was wondering why.
Expedient asked 11/6, 2011 at 15:34

7

Solved

I have read some articles on polymorphism. But I think I could not quite grasp the meaning of its importance. Most of the articles don't say why it is important and how I can achieve polymorphic be...

2

Solved

A typical factory design pattern require the base class to declare virtual destructor, but this can be actually avoided using shared_ptr. #include <iostream> #include <memory> #include...
Colored asked 28/4, 2016 at 16:52

2

Solved

To quote the Book (emphasis mine), The same is true of generic type parameters that are filled in with concrete type parameters when the trait is used: the concrete types become part of the type t...
Warwick asked 31/5, 2021 at 2:10

8

Solved

In Why is there no base class in C++?, I quoted Stroustrup on why a common Object class for all classes is problematic in c++. In that quote there is the statement: Using a universal base class im...
Raddled asked 5/5, 2011 at 8:33

10

Solved

I have a base class with a property which (the get method) I want to overwrite in the subclass. My first thought was something like: class Foo(object): def _get_age(self): return 11 age = prop...
Exercise asked 26/10, 2008 at 2:49

2

Solved

I find pretty weird that use std::sync::Arc; trait Fruit {} struct Pear {} impl Fruit for Pear {} fn main() { let pear = Arc::new(Pear {}); let cloned = Arc::clone(&pear); let cloned_caste...
Fatty asked 10/5, 2021 at 9:50

1

Solved

What I want to achieve is probably easily explained: Consider I have an abstract class that I know will contain multiple objects of known type. However the actual container holding these objects wi...
Chitterlings asked 30/4, 2021 at 14:52

© 2022 - 2024 — McMap. All rights reserved.