Skip to main content

Questions tagged [virtual-functions]

Filter by
Sorted by
Tagged with
0 votes
2 answers
272 views

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 ...
Nick's user avatar
  • 305
2 votes
3 answers
680 views

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, ...
ThePunisher's user avatar
3 votes
3 answers
4k views

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 ...
Daniel's user avatar
  • 217
24 votes
4 answers
7k views

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 ...
Peter Perot's user avatar
1 vote
1 answer
326 views

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 ...
ZeroZ30o's user avatar
  • 121
2 votes
4 answers
2k views

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 ...
Doug Tait's user avatar
-9 votes
1 answer
974 views

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 ...
user104449's user avatar
3 votes
1 answer
5k views

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)...
kevinarpe's user avatar
  • 263
3 votes
3 answers
4k views

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 ...
broun's user avatar
  • 139
5 votes
1 answer
19k views

#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 ...
solti's user avatar
  • 379
1 vote
1 answer
89 views

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 ...
Den's user avatar
  • 4,887
32 votes
1 answer
7k views

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?
Mawg's user avatar
  • 4,308