Template parsing
Consider the following line of code:
a < b , c > d;
How would you parse this? There are actually two ways, depending on what a
, b
, c
and d
are. Firstly, a variable declaration
a<b,c> d;
^^^^^^ ^
Type Var
in the case that a
is a known template type, b
and c
are other known types. Secondly,
a<b , c<d ;
^^^ ^^^
boolean expressions
in the case that a
, b
, c
and d
are all variables of some sort.
The vexing parse
Or here another one:
a b(c); // is 'b' a function or a variable?
This could be a function declaration (a function with return type a
and argument type c
) or a variable definition (whose type is a
and whose constructor argument is c
).
Conclusion
There's a lot of stuff like that, unfortunately. I'm not sure, if it would be impossible to write a compiler that can deal with that kind of stuff, but it would at least be very hard to write one. Compilation times are a serious issue in C++ already. This would only make it worse. Also: It is good practice to only use what you have defined or declared already, even in other languages.
Constraints of the committee
Even if it would be reasonably possible to implement this feature, it would kill backwards compatibility. Function overloading resolution only takes prior declarations into account and the interpretation of function calls may change depending on the place a function call is written. That's the way C++ is put together. Now, the C++ standards committee is big on back-wards compatibility. In particular: They do not want to break any existing code (and rightly so). Your proposal would surely break existing code which is a no-go for the language designers.