问题
The following code snippet compiles only if I explicitly specify the template argument T
for the Base
struct in Derived
ctor:
template <class T>
struct Base
{
Base(int) {}
};
template <class T>
struct Derived : Base<T>
{
Derived(int i) : Base<T>(i) {}
};
If I call Base(i)
instead of Base<T>(i)
- it doesn't work. Why can't compiler determine that Base
is actually Base<T>
(because I derive from Base<T>
)? Is this requirement made intentionally?
来源:https://stackoverflow.com/questions/52632748/why-must-we-specify-template-arguments-for-template-base-class-when-calling-its