I have this code below which I was trying out from a course I was undertaking, that pretty much does what is expected to do
#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;
}
But I don't understand how the parts below work. I understand how the default parameters part of the template work, but don't understand how the code creates an object once the template class is instantiated.
A<char, int>('A', 65);
A<char, char>('A', 'A');
Why isn't an explicit object created like for the first case with A<char> a('A', 'A');
? I saw no compilation errors compiling with g++ -Wall -Wextra --std=c++11
. Also if a specific clause from cppreference that explains this behavior would be appreciated, as I've missed identifying where does such a behavior is explained.