T
Tom
FAQ 158 is about correct usage of OO. I am struggling to understand
how the correct function is selected. Three derived classes from base
class "Printer2". Where is the logic that selects from the three
over-rides? That small decoration "p" in the next to last line of code
seems to be the key. This rookie just doesn't 'get it'. Thanks for any
help.
Below is a copy of the FAQ 158 program:
=========================================
class Printer2 {
public :
virtual ~Printer2( ) { }
virtual void italics(const char* s) = 0;
};
class EpsonPrinter2 : public Printer2 {
public :
virtual void intalics(const char* s)
{ cout << esc << "i+" << s << esc << "i-"; }
};
class ProprinterPrinter2 : public Printer2 {
public :
virtual void intalics(const char* s)
{ cout << esc << "[i" << s << esc << "[n"; }
};
class StarPrinter2 : public Printer2 {
public :
virtual void intalics(const char* s)
{ cout << esc << "x" << s << esc << "y"; }
};
void
printUsingItalics ( Printer2& p, const char* s)
{
p.italics(s);
}
how the correct function is selected. Three derived classes from base
class "Printer2". Where is the logic that selects from the three
over-rides? That small decoration "p" in the next to last line of code
seems to be the key. This rookie just doesn't 'get it'. Thanks for any
help.
Below is a copy of the FAQ 158 program:
=========================================
class Printer2 {
public :
virtual ~Printer2( ) { }
virtual void italics(const char* s) = 0;
};
class EpsonPrinter2 : public Printer2 {
public :
virtual void intalics(const char* s)
{ cout << esc << "i+" << s << esc << "i-"; }
};
class ProprinterPrinter2 : public Printer2 {
public :
virtual void intalics(const char* s)
{ cout << esc << "[i" << s << esc << "[n"; }
};
class StarPrinter2 : public Printer2 {
public :
virtual void intalics(const char* s)
{ cout << esc << "x" << s << esc << "y"; }
};
void
printUsingItalics ( Printer2& p, const char* s)
{
p.italics(s);
}