嵌套模板歧义

问题描述 投票:1回答:1

嵌套模板要求使用template关键字,如此answer中所述。这是一个简短的演示,它会导致编译器错误:

template <int T>
struct A {
  template <int U>
  static void b(int x) {
  }
};

template <int T>
void test() {
  A<T>::b<T>(T); // Should be:
  // A<T>::template b<T>(T);
}

int main() {
  test<0>();
}

[作为挑战,我试图考虑一个程序,其中两种可能性(带有或不带有template)都是有效的,但是具有两种不同的含义,但是我无法全神贯注于运营商超载业务。是否可以使A<T>::b<T>(T);为有效语句?

c++ templates
1个回答
0
投票

如果您将struct A更改为:

© www.soinside.com 2019 - 2024. All rights reserved.