In C++, is it possible to require a method in a base class to be overridden by all of its derived classes without making it a pure virtual method?
#include <iostream>
using namespace std;
class BaseClass{
public:
int printStuff(){ //find some way to require all derived classes to override this method
cout << "Printing some stuff";
}
};
class DerivedClass: public BaseClass{
};
int main(){
cout << "Hello World!";
return 0;
}
I know you said you didn’t want to use pure virtual functions, but you can use pure virtual functions and still give the method a definition if that’s what you are trying to do (not sure if you knew that already):