This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Question about inheritance


> 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"?

This is really not an egcs question, so I suggest to take it to one of
the C++ newsgroups. The best way of doing what you want depends on
your application; if this is really about printing "int" and
"something else", templates are for you:

template<typename T>
class foo
{
public:
	typedef T hi;

	void doit (void)
	{
		if (sizeof(hi) == sizeof(int))
			puts("int");
		else
			puts("something else");
	}
};

int
main ()
{
	foo<double> s;

	s.doit();
}

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]