In the following C++ code, a template placeholder in argument of function fun1
, and in the return type of function ret1
, does not compile:
template <typename T = int>
class type {
T data;
};
void fun1(type arg); // Error: template placeholder not permitted in this context
void fun2(type<> arg); // Ok
void fun3(type<int> arg); // Ok
type ret1(); // Error: Deduced class type 'type' in function return type
type<> ret2(); // Ok
type<int> ret3(); // Ok
int main() {
type var1; // Ok!!!!!!
type<> var2; // Ok
type<int> var3; // Ok
}
But, var1
is ok.
- Why does
var1
compile, butfun1
andret1
do not? - Is there any logic behind this inconsistent behavior between function declarations and variable declarations?