Polymorphism in regular variadic function

Bill Baxter wbaxter at gmail.com
Mon Dec 4 17:42:26 PST 2006


Is there any way to check if an argument is type T or anything derived 
from it using the TypeInfo?

Basically I want this:

class Foo { int x = 3; }
class Bar : Foo { long y = 4; }

void printargs(...)
{
     printf("%d arguments\n", _arguments.length);
     for (int i = 0; i < _arguments.length; i++)
     {   _arguments[i].print();

         // Want to accept Foo or anything derived from Foo here!
	if (_arguments[i] == typeid(Foo))
	{
	    Foo f = *cast(Foo*)_argptr;
	    _argptr += Foo.sizeof;
	    printf("\t%p\n", f);
	}
	else
	    assert(0);
     }
}


--bb



More information about the Digitalmars-d-learn mailing list