Question about inheritance
Peter V. Evans
pevans@enteract.com
Mon Aug 3 13:54:00 GMT 1998
Hi,
I'm developing a program which makes heavy usage of inheritance. Let me
give the example first:
class foo
{
public:
typedef int hi;
void doit (void)
{
if (sizeof(hi) == sizeof(int))
puts("int");
else
puts("something else");
}
};
class stuff : public foo
{
public:
typedef double hi;
};
int
main (void)
{
stuff s;
s.doit(); // Prints out "int", not "something else"
return 0;
}
---
The function doit, thus, does not see the derived class' "hi", only the
parent class. I couldn't say if this is the correct behaviour, since I
don't know C++ as well as most others, but a better question would be,
how to get doit to somehow see the derived class "hi" instead of the
parent class "hi"?
Thanks for any help you can provide.
Peter
More information about the Gcc
mailing list