I have created an abstract base class, which has a pure virtual method with default argument.
class Base {
...
virtual someMethod(const SomeStruct& t = 0) = 0;
...
}
class Derived : public Base {
...
virtual someMethod(const SomeStruct& t = 0);
...
}
So I would like to know is it a good practice to set the default argument to pure virtual and overall to virtual methods?
I often wish to use both default parameters and virtual function as you do. The others have rightfully pointed out however that this leads to ambiguity and is generally not a good idea. There is a reasonably simple solution, one that I use. Give your virtual function a different name, make it protected, and then provide a public function with default parameters which calls it.
Derived classes simply override
vSomeMethodand don’t worry at all about the default parameters.