The at at feature is also included. C ++ will try to infer a template type argument. This is what happens in your code since you are not specifying a type in the call, such as a.at <size_t> (1);
This code will generate a warning because it inferred the type as unsigned int, and then we will try to pass size_t
template <typename T> class A { int t; public: template<typename I> T& at(const I i) { return t;} }; int main() { unsigned int j = 5; size_t i = 10; A<int> a; a.at(j) = 4;
EDIT: I really tried this code in VS and generated a warning.
Edit2: In the code I tried, size_t and unsigned int are both 4 bytes too. So I did the digging. In older versions of VS, size_t is defined as typedef __w64 unsigned int size_t Now "__w64" is outdated, but was used to indicate types that would have a different size (for example, 64 vs 32) when switching to a 64-bit platform. __w64 causes the compiler to see size_t as another type.
As an experiment, I typed my own unsigned int myint and changed the line size_t i = 10 to myint i = 10 .
using typedef __w64 unsigned int myint generates a warning, where "typedef unsigned int myint" does not generate a warning.
source share