我在下面有这段代码,我正在尝试我正在学习的课程,这几乎可以做到预期做的事情
#include <iostream>
template <typename T, class U = int>
class A {
public:
T x;
U y;
A(T x, U y) { std::cout << x << " " << y << std::endl; }
};
int main() {
A<char> a('A', 'A');
A<char, int>('A', 65);
A<char, char>('A', 'A');
return 0;
}
但我不明白下面的部分是如何工作的。我了解模板的默认参数部分如何工作,但不了解模板类实例化后代码如何创建对象。
A<char, int>('A', 65);
A<char, char>('A', 'A');
为什么不像第一种情况那样创建显式对象A<char> a('A', 'A');
?我没有看到使用g++ -Wall -Wextra --std=c++11
. 此外,如果 cppreference 中解释此行为的特定子句将不胜感激,因为我错过了确定在哪里解释了这种行为。