Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Template (C++)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Feature in the C++ programming language}} {{Redirect|Template (computer programming)||Template (disambiguation)#Computing{{!}}Template Β§ Computing}} {{Multiple issues| {{Update|reason=This article omits features of templates that were introduced in [[C++17]] or [[C++20]]|date=August 2021}} {{More citations needed|date=January 2009}} {{More footnotes needed|date=May 2009}} {{Coat|date=March 2024}} }} '''Templates''' are a feature of the [[C++]] programming language that allows [[Function (computer programming)|functions]] and [[Class (computer programming)|classes]] to operate with [[Generic programming|generic types]]. This allows a function or class [[Declaration (computer programming)|declaration]] to reference via a generic [[Variable (computer science)|variable]] another different class (built-in or newly declared [[data type]]) without creating full declaration for each of these different classes. In plain terms, a templated class or function would be the equivalent of (before "compiling") copying and pasting the templated block of code where it is used, and then replacing the template parameter with the actual one. For this reason, classes employing templated methods place the implementation in the headers (*.h files) as no symbol could be compiled without knowing the type beforehand. The [[C++ Standard Library]] provides many useful functions within a framework of connected templates. Major inspirations for C++ templates were the parameterized modules provided by the language [[CLU (programming language)|CLU]] and the generics provided by [[Ada (programming language)|Ada]].<ref name="Stroustrup">{{cite web |last=Stroustrup |first=Bjarne |author-link=Bjarne Stroustrup |date=8 September 2004 |title=The C++ Programming Language |edition=3rd, Special |url=http://www.stroustrup.com/ |work=Stroustrup.com (personal homepage)}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)