Possible Duplicate:
Calling virtual function of derived class from base class constructor?
I have the following files (forgive typos, I rewriting the code fast from memory)
BaseReader(){
openFile();
}
void BaseReader::openFile(){
//logic to open file
}
Open file is declared as virtual public method (it was protected, but I swtiched it to public while trying to figure out what is wrong) in the .h. SortReader is defined as:
class SortReader: public BaseReader{
public:
SortReader();
void openFile();
};
with the following code:
SortReader::SortReader(): BaseReader(){}
SortReader::openFile(){
sortFile();
BaseReader::openFile();
}
When I Try constructing a SortReader object the sortFile method is never called. I can walk through it in a debugger and watch the SortReader call the BaseReader constructor The BaseReader constructor calls openFile which calls the BaseReader version of openFile. I want it to call SortReader's implimentation of open file. What do I need to do to have that happen?