For the template method argument of the class Foo, are "Foo &" and "Foo <T> &" the same?
Consider the class
template <typename T>
struct Foo {
Foo(const Foo<T>& other) {}
};
For the type of argument to the constructor, there const Foo<T>&and const Foo&the same thing in this context? I always assumed that it cannot be considered the last for Foo<int> f = Foo<float>(), but the first cannot. But now I'm not sure that it is.
+4
2 answers
In a class template, the parameters of the class template have one unique value for each instance. This means that it Foo<int>has T==int, and therefore templated ctor Foo<int>::Foo(const Foo<int>& other).
Perhaps there are additional template options:
template <typename T>
struct Foo {
template <typename U>
Foo(const Foo<U>& other) {}
};
Now Tmay differ from U.
+8