我和朋友正在讨论C++模板.他问我应该做什么:
#include <iostream>
template <bool>
struct A {
A(bool) { std::cout << "bool\n"; }
A(void*) { std::cout << "void*\n"; }
};
int main() {
A<true> *d = 0;
const int b = 2;
const int c = 1;
new A< b > (c) > (d);
}
Run Code Online (Sandbox Code Playgroud)
main中的最后一行有两个合理的解析.'b'是模板参数还是b > (c)模板参数?
虽然编译这个很简单,看看我们得到了什么,但我们想知道是什么解决了歧义?