c++ - Why and how can an object file of old code use new code that uses the generic programming paradigm even though templates are static binding? -


this entirely different question 1 asked before why i'm posting this.

i define topic subjective question inspires answers explain "why" , "how". allowed according help center rules.

in order make question more constructive, provide resources better explain topic.

from c++ superfaq under question

"can give me simple reason why virtual functions (dynamic binding, dynamic polymorphism) , templates (static polymorphism) make big difference?"

the author says, "...a programmer might write code called framework written great, great grandfather. there’s no need change great-great-grandpa’s code. in fact, dynamic binding virtual functions, doesn’t need recompiled.even if have left object file , source code great-great-grandpa wrote lost 25 years ago, ancient object file call new extension without falling apart."

he goes on say, "that extensibility, , oo , generic programming powerful reusable abstraction."

furthermore, read paper written creator of c++ bjarne stroustrup called, "why c++ not object-oriented programming language". in paper, defines language or technique object-oriented if , if directly supports:

  1. abstraction – providing form of classes , objects.

  2. inheritance – providing ability build new abstractions out of existing ones.

  3. run-time polymorphism – providing form of run-time binding.

he briefly mentions generic programming.

6.7 generic programming - major theme in c ++ community on last few years has been development of techniques exploiting template mechanism.

from reading these 2 resources can understand how old code able use new code means of object-oriented paradigm. however, not understand how old code can use new code use of generic programming (in case templates) because generic programming uses static binding. previous related question ben voigt commented that,

"for "old" template code combined "new" template code, necessary both compiled together."

the c++ superfaq seems imply (for both oo , generic programming) old code should not have recompiled new code in order use new code, , should need object file old code. thereby, maintaining code reusability.

could please answer "why" , "how" object file of old code can use new code uses generic programming paradigm though templates static binding?

edit

i explain answer below in little more detail since me understand more , may others understand. since generic programming uses static binding, both source code of old code , of new code must re-compiled "together" code reusability take effect. means, if have object file of old code, not able use new code since require dynamic/late binding binding @ run-time.

the short answer can't. i'd guess that's first sentence of answer linked intended say:

they can improve reuse letting old code call new code provided @ run time (virtual functions) or compile time (templates).

[emphasis added]

for existing code make use of templates, do have re-compile. means have start (some form of) source code, not object files (at least not people think of normal object files, anyway).


Popular posts from this blog