Skip to main content
0 votes
2 answers
62 views

The following code works: fn do_it_fun<I>(words: Vec<&str>, inputs: I) where I: AsRef<[&'static str]> { for word in words { if inputs.as_ref().into_iter()...
gust's user avatar
  • 965
-1 votes
1 answer
65 views

I’m really confused about what polymorphism in OOP actually means. Everyone explains it differently, and I’m not sure which definition is correct: In some places, polymorphism is explained as dynamic ...
Ado's user avatar
  • 55
1 vote
2 answers
114 views

I want to store several different callable objects (different types) in a container (e.g. std::array) in order to invoke them later. Each callable has the same return type and the same amount and type ...
breiters's user avatar
  • 158
1 vote
0 answers
119 views

I know that because of virtual tables, cache misses and memory allocation for pointers to the base class, dynamic polymorphism is slow. Especially when compared to static polymorphism. I decided to ...
OHtuzh's user avatar
  • 29
0 votes
1 answer
75 views

This a snippet from the real code, but the idea is that i want to print the service type in my log. In this example i'm trying to print it, but i get an exception, and i don't know why. I have other ...
eniac's user avatar
  • 63
3 votes
1 answer
251 views

so I believe I understand polymorphism with single inheritance, where say you have classes Dog and Cat inherit from an interface Animal and Animal has a Speak and Walk function so then you generate v ...
IrrelevantGaymer 's user avatar
1 vote
1 answer
159 views

In order to store CRTP object pointers in a homogenous container the templated base class can itself be derived from a class common_base that defines a pure virtual interface and (if required) a ...
sleep's user avatar
  • 4,974
-4 votes
1 answer
80 views

The following code could not be compiled: in generic class LM Java unable to resolve which of "static server()" methods to call. On the other hand, I'm not able to add any "instanceof&...
AlexDem's user avatar
3 votes
2 answers
3k views

I wonder if there is any benefit of using CRTP over virtual function polymorphism if I never invoke the function from the base class (i.e., virtual dispatch)? Here are the sample code. The disassembly ...
Yuanyi Wu's user avatar
  • 339
0 votes
0 answers
26 views

I need to mock an external dependency for unit test since it is not deterministic. The dependency class cannot be abstracted out with an interface and dependency-injected into the constructor since it ...
atab's user avatar
  • 1
0 votes
1 answer
156 views

My questions are: Why method hiding is also an example of compile time polymorphism while it is not overridden? Related code: class A{ public static void print(){ System.out.println("...
tú nguyệt's user avatar
0 votes
2 answers
463 views

I want to implement polymorphism statically with CRTP. I want to create several base classes that provide functionalities. However the functionalities can be overlapping. However if they overlap, they ...
marco's user avatar
  • 187
1 vote
1 answer
394 views

If you want to have different public interfaces for one and the same object, you can use virtual base classes. But those have overhead (memory and space). class View1 { public: int x; } class ...
Sebastian's user avatar
  • 2,014
6 votes
2 answers
3k views

I was following this blog and was trying to replace a dynamic polymorphism code into using std::variant and std::visit. But I can not get std::variant + std::visit to work better than a virtual struct ...
n1r44's user avatar
  • 610
0 votes
1 answer
342 views

Let's say I have following C++ code class ControlAlgorithm { public: virtual void update() = 0; virtual void enable() = 0; virtual void disable() = 0; }; class Algorithm_A : public ...
Steve's user avatar
  • 869

15 30 50 per page
1
2 3 4 5
7