Template functions, can we make it more simple?
SteveGuo
steveguo at outlook.com
Fri Aug 2 16:32:39 PDT 2013
class A
{
auto n;
void foo(auto x) { ... }
}
int main()
{
scope a = new A;
scope b = new A;
a.foo(1); // this means A has a member function "void foo(int
x) {...}"
a.foo(1.1); // this means A has another member function "void
foo(double x) {...}"
// compiler will automatically build two versions of function
"foo"
b.foo("Hello"); // this means A has a third "foo" member
function with parameter "string []"
a.n = 1.3; // class A(type 1), which has a data member double
n;
b.n = 1 // class A(type 2), which has a data member int n;
/*
So there are two class type A1 and A2
class A1
{
double n;
void foo(int x) { ... }
}
class A2
{
int n;
void foo(double x) { ... }
}
*/
}
More information about the Digitalmars-d
mailing list