I can't believe I never ran into this problem before.
Code:
struct first
{
virtual int function(int a, int b)
{
/* whatever */
}
virtual int function(int a)
{
return function(a, 0);
}
virtual int function(void)
{
return function(0);
}
};
struct second : first
{
void stuff()
{
/* whatever */
}
virtual int function(int a, int b)
{
stuff();
return first::function(a, b);
}
};
int main()
{
second obj;
return obj.function();
}
At this point, the compiler complains that 'struct second' has no function with that signature, because I overided one of the functions having the same name. Stupid. Any compiler worth it's salt should be able to sort that out!
Anyway, so what's to do? Redefine each function? Then I came up with a work-around, though it's a bit of a hack, and demands a new discipline altogether.
The function with the most parameters is the 'lowest common denominator' (LCD) (since all others ultimately call that one internally). So here's what I did:
Code:
struct first
{
virtual int lcd_function(int a, int b)
{
/* whatever */
}
virtual int function(int a, int b)
{
return lcd_function(a, b);
}
virtual int function(int a)
{
return function(a, 0);
}
virtual int function(void)
{
return function(0);
}
};
struct second : first
{
void stuff()
{
/* whatever */
}
virtual int lcd_function(int a, int b)
{
stuff();
return first::lcd_function(a, b);
}
};
int main()
{
second obj;
return obj.function();
}
Voila.
OK, so if anyone can come up with a better solution - please let me know. I'm glad it works, on the one hand, but disappointed that I may have to incorporate this feature into future code!
Any suggestions are welcome.