Templates lots of newbie qs.
Chris Warwick
sp at m.me.not
Thu Mar 8 12:05:34 PST 2007
"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
news:espjmc$1d51$1 at digitalmars.com...
> "Chris Warwick" <sp at m.me.not> wrote in message
> news:espgo1$16ge$1 at digitalmars.com...
>>
>> IFTI?
>
> ...you can just type "functionName(params)".
>
> IFTI stands for "Implicit Function Template Instantiation." When you
> write a templated function:
>
> T func(T)(T val)
> {
> return val;
> }
>
> You don't want to have to type out:
>
> func!(int)(4);
> func!(char[])("hi");
>
> So IFTI can implicitly determine what T should be by looking at the
> parameter list:
>
> func(4); // T is determined to be int
> func("hello"); // T is determined to be char[]
>
> It's a very useful feature.
So say you have the following...
int indexOf(T)(T[] arr, T item)
{
// search for and return index
}
class Foo()
{
Bar[] fitems;
int indexOf(Bar b)
{
fitems.indexOf(b); // <--- name clash
}
}
How do you get fitems.indexOf to resolve to the templated array property and
not the local function of the same name? Obviously it should resolve to the
local symbol but i cant figure out how to help teh compiler know i want it
to use the template version of indexOf.
thanks,
cw
More information about the Digitalmars-d-learn
mailing list