I was doing a comparison between C++ and Delphi and I found something tricky to me.
This is very easy C++ code:
template<typename T>
class C {
class D {
T x;
}
}
In this scenario, we have that the class C is a template class ( = generic class) and the nested class D is also a template class. If T is a double, the x inside D is double.
I cannot say this:
template<typename T>
class C {
template<typename T>
class D {
T x;
}
}
That is an error since I am already "inside" C and another T would be a conflict. To fix the error, I should use a different name, like U.
template<typename T>
class C {
template<typename U>
class D {
T x;
}
}
In Delphi, I could write this:
type
TClassC<T> = class
private
type
TClassD = class
private
x: T;
end;
end;
If T is an integer, now x is an integer since (from what I've understood reading online) the TClassD is integer. In Delphi this is also legal:
type
TClassC<T> = class
private
type
TClassD<T> = class // <-- note the <T> repeated!!
private
x: T;
end;
end;
What about now? If I am able to declare T again in TClassD, this means that without the <T> I'd have a non-generic TClassD class. Am I correct?