Questions tagged [virtual-functions]
The virtual-functions tag has no summary.
23 questions
0
votes
2
answers
272
views
Help with optimizing virtual method
I am developing a key / value database
https://github.com/nmmmnu/HM4
Currently I have following commands
XNSUM - sum keys with same prefix
XRSUM - sum keys from some range
XNCOUNT - count keys with ...
2
votes
3
answers
680
views
Object Oriented Programming - what is the best way to add new parameters?
I have a doubt about what would be the right OOP approach for implementing classes that do similar stuff with different parameters.
To provide a simple example, I would use two polynomial classes, ...
3
votes
3
answers
4k
views
True cost of virtual dispatch in C++ - when stop using it?
What I've learned so far as a programmer has lead me to think that the easiest way to write large scale software is to use a lot of interfaces - this makes things very easy to isolate and test. In ...
24
votes
4
answers
7k
views
Never make public members virtual/abstract - really?
Back in the 2000s a colleague of mine told me that it is an anti-pattern to make public methods virtual or abstract.
For example, he considered a class like this not well designed:
public abstract ...
1
vote
1
answer
326
views
Differences between branching and virtual methods
I was trying to find more info on the matter but could only find this:
In C++ why and how are virtual functions slower?
The answer says that the virtual call "Get[s] the right function address from ...
2
votes
4
answers
2k
views
Should a base class implement a virtual method for the most common type or derived class?
Is it okay to implement a virtual method in a base class because I know that the majority of derived classes will use that particular implementation?
Suppose I have the following class hierarchy (in ...
-9
votes
1
answer
974
views
Why runtime ploymorphism is required? [closed]
Why runtime ploymorphism is required ? give a real example that "why it came into existence when we have compile time polymorphism??" As mainting the runtime polymorphism requires lot of overhead of ...
3
votes
1
answer
5k
views
What are the consequences of no virtual destructor for this base class?
I found this same code here:
https://stackoverflow.com/a/5854862/257299
struct Base { virtual Base& operator+=(int) = 0; };
struct X : Base
{
X(int n) : n_(n) { }
X& operator+=(int n)...
3
votes
3
answers
4k
views
When to mark a function as virtual?
I'm trying to understand the idiomatic way to code. I'm using gmock to unit test the components I write. Gmock requires methods to be virtual to be able to mock but the class I'm trying to mock has a ...
5
votes
1
answer
19k
views
How does the base class non-virtual function get called when derived class object is assigned to base class?
#include <iostream>
class Base {
private:
int b_value;
public:
void my_func() {std::cout << "This is Base's non-virutal my_func()" << std::endl; }
virtual void ...
1
vote
1
answer
89
views
Virtual method returning a unique collection - how to ensure and hint?
I have a virtual method that returns a collection of items that must be unique. I want to make sure that it will be obvious when overriding the method. What is the best way to do this?
Here is an ...
32
votes
1
answer
7k
views
Why does C++ not have a "pure" keyword for virtual functions?
I have always wondered why we code
virtual void MyFunction() = 0;
and not
pure virtual void MyFunction();
Is there a reference for the basis of this decision?