Thread View: gnu.g++.help
1 messages
1 total messages
Started by Mike Tiller
Fri, 30 Oct 1992 15:44
Templates & Down-Casting
Author: Mike Tiller
Date: Fri, 30 Oct 1992 15:44
Date: Fri, 30 Oct 1992 15:44
48 lines
1291 bytes
1291 bytes
I realize the g++ implementation of templates is incomplete, but
I have a question about the template mechanism in general.
Lets say you have classes like:
class Base
{
...
};
class Sub : public Base
{
...
};
template<class T>
class Array
{
...
};
And the following code:
void Sort(Array<Base *>& ba)
{
...
}
main()
{
Array<Base *> ba;
Array<Sub *> sa;
Sort(ba);
Sort(sa); // This line gives you an error
}
My question is, is there some clever design trick to circumvent
this restriction? Does anyone know what the "standard" has to
say about this? I looked in the ARM, didn't seem to say much on
this subject. I could see why this would cause problems if
the sizeof(Base *) != sizeof(Sub *). Is there a reason for
restrictions like this? (I am certainly not an expert on such
things)
Thanks
Michael Tiller
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads