Template parameter shadowing

klickverbot see at klickverbot.at
Wed Sep 22 04:52:56 PDT 2010


In short, should the following be allowed?

---
class Class(T) {
   string foo(T)(T arg) {
     return T.stringof;
   }

   string bar() {
     return T.stringof;
   }
}

unittest {
   auto c = new Class!int;
   assert(c.foo("asdf") == "string");
   assert(c.bar() == "int");
}
---

Note that the T type parameter to the template function shadows the one 
from the template class, which might be a source of confusion since T 
refers to class template parameter in other member functions.


More information about the Digitalmars-d mailing list