I have this code snippet. I come from a Java background. I don't understand why the BubbleSort class sort method can access a private method in its base class and override it? This code snippet compiles and there is no error. in BubbleSort class, I am overriding the sortData method but the sortData method is private in the base class so practically Bubblesort class shouldn't be able to see it, let alone let me override the method.
#include <iostream>
class Sort{
public:
virtual void processData() final {
readData();
sortData();
writeData();
}
private:
virtual void readData(){}
virtual void sortData()= 0;
virtual void writeData(){}
};
class BubbleSort: public Sort{
private:
void sortData() override {
std::cout << "sortData" << std::endl;
}
};
int main(){
std::cout << std::endl;
Sort* sort = new BubbleSort();
sort->processData();
std::cout << std::endl;
}