#include <iostream>
using namespace std;
namespace xyz {
class Base {
public:
bool configure (double a) {
cout << "Do nothing. a is currently equal to: " << a << endl;
return true;
}
virtual bool update(float& a)=0;
};
}
class Child : public xyz::Base {
public:
virtual bool update(float& a) {
a = a+0.5;
cout << "Updated" << endl;
return false;
}
};
int main() {
cout << "Hello World" << endl;
Child median;
float a = 3.0;
median.update(a);
median.xyz::Base::configure(a);
return 0;
}
I think I miss some C++ concept here.
I am totally lost how median.xyz::Base::configure(a); this line is even a thing. Which is a class instance (object) median dot a namespace:: xyz and then :: notation to the parent class Base that I have only used for static class methods (but configure (double a) is not even static...).
How can this be explained to even work/compile?
This is a simplified MWE from a robotics library that I modified so that it is more generic (https://github.com/ANYbotics/grid_map/blob/master/grid_map_filters/include/grid_map_filters/MedianFillFilter.hpp)
What you are seeing here is explicitly calling the base class version of the function. For example if you had
then
median.configure(a);will printIn Child::configure. a is currently equal to: 3.5as it is calling theChildversion of the function. By usingit will instead print
Do nothing. a is currently equal to: 3.5as it is now explicitly using theBaseversion of the function. You can see the output change in this live example.