c++ - Why allow function declarations inside function bodies -


why syntax allow function declarations inside function bodies?

it create lot of questions here on function declarations mistaken variable initializations , like.

a object(); 

not mention vexing parse.

is there use-case not achieved more common scope hiding means namespaces , members?

is historical reasons?

addendum: if historical reasons, inherited c limit scope, problem banning them?

whilst many c++ applications written solely in c++ code, there lot of code mixture of c , c++ code. mixture of c++'s important part of usefulness (including "easy" interfacing existing api's, opengl or curl custom hardware drivers written in c, can pretty used directly little effort, trying interface custom hardware c driver basic interpreter pretty diffcult)

if start breaking compatibility removing things "for no particular value", c++ no longer useful. aside giving better error messages in condition confusing, of course useful in itself, it's hard see how it's useful remove - , that's of course assuming none of c++ using in - , wouldn't surprised if happen @ times in modern code (for whatever or bad reasons).

in general, c++ tries hard not break backwards compatibility - , this, in mind, thing. that's why keyword static used bunch of different things, rather adding new keyword, , auto means different used in c, it's not "new" keyword break existing code happened use whatever other word chosen (and small break, nobody used past 20 years anyway).


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -