0

In https://github.com/pytorch/pytorch/blob/dc2cdeae68a6ffc6be24a9dee75ccea745936657/aten/src/ATen/native/quantized/cpu/qupsample_nearest2d.cpp#L40, we see typename used in the function call to the template function reinterpret_cast.

I've never seen a function call where the typename keyword was used.

I tried this with a simple code but the program doesn't compile:

template <typename T>
void func(T i) {
}

int main(int argc, char const *argv[])
{
  func<typename int> func(1);
}
test.cpp:19:17: error: expected a qualified name after 'typename'
  func<typename int> func(1);
jinkins
  • 25
  • 1
  • 6
  • @user17732522 hmm, but there weren't any compiler errors in the PR that I linked, so it seems it compiled fine – jinkins Mar 25 '22 at 13:15
  • I meant that the code in your question is not valid C++. `typename` can only appear before a qualified-id. In the linked code the context is a very different one. The duplicate explains when it is allowed and required. – user17732522 Mar 25 '22 at 13:15
  • `reinterpret_cast(idata);` and `func func(1);` are two completly different things. I've closed this as a duplcuate that explains why `typename` is needed in code you saw. – NathanOliver Mar 25 '22 at 13:15
  • `reinterpret_cast` is a keyword, not a function. Now a cast-expression looks a lot like a function call expression, so the confusion is understandable. As an example of the differences, functions have addresses but `reinterpret_cast` does not. – MSalters Mar 25 '22 at 13:40
  • Key phrase from the error message: "qualified name". A qualified name will have `::` in it. An unqualified name will not. – JaMiT Mar 25 '22 at 13:47

0 Answers0