The virtual-functions tag has no usage guidance.
2
votes
3answers
144 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 ...
0
votes
1answer
92 views
Is it possible to detect misuse of passing self type argument in compile time?
I just hit the very basic problem in OOP and I cannot see any working solution except postponing appropriate check until run time.
It is pretty clear notion of an action "do something with value of ...
0
votes
1answer
113 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
1answer
82 views
Pass data into a constructor or instead create virtual methods?
In an object oriented module describing a database, should I pass DB description data structures to the constructor in the constructors of derived classes, or should I instead create ("virtual" that ...
1
vote
1answer
65 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 ...
21
votes
8answers
8k views
When NOT to use virtual destructors?
I believed I searched many times about virtual destructors, most mention the purpose of virtual destructors, and why you need virtual destructors. Also I think in most cases destructors need to be ...
27
votes
1answer
3k 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?