<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C++ Tutorial - Templates</title><link>/technologies/code_exchange/b/blog/posts/c-tutorial---templates</link><description>IntroductionIn the previous tutorial , we used the STL (Standard Template Library) implementations of dynamic lists. More specifically, we looked at the forward_list, the list, and the vector. We showed how to use them and talked about whi...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: C++ Tutorial - Templates</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/c-tutorial---templates</link><pubDate>Thu, 06 Jul 2017 08:27:16 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:75f6caa6-c8b3-40dd-82b5-101daa689541</guid><dc:creator>raspgraph</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I have followed your program and think I have this right as you described in your text.&lt;/p&gt;&lt;p&gt;int main()&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp; double d1 = 2.3;&lt;/p&gt;&lt;p&gt;&amp;nbsp; double d2 = 3.4;&lt;/p&gt;&lt;p&gt;&amp;nbsp; cout &amp;lt;&amp;lt; Add(d1, d2) &amp;lt;&amp;lt; endl;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; int i1 = 4;&lt;/p&gt;&lt;p&gt;&amp;nbsp; int i2 = 5;&lt;/p&gt;&lt;p&gt;&amp;nbsp; cout &amp;lt;&amp;lt; Add(i1, i2) &amp;lt;&amp;lt; endl;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; return 0;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;template &amp;lt;class T&amp;gt;&lt;/p&gt;&lt;p&gt;T Add(T a, T b)&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&amp;nbsp; return a + b;&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;BUT the template doesn&amp;#39;t seem to relate to main.&lt;/p&gt;&lt;p&gt;following errors occur when compiling within raspberry pi terminal&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;pi@raspberrypi:~/Desktop $ g++ -std=c++0x 05_template.cpp -o05_template&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;05_template.cpp: In function ‘int main()’:&lt;/p&gt;&lt;p&gt;05_template.cpp:5:2: error: ‘cout’ was not declared in this scope&lt;/p&gt;&lt;p&gt;&amp;nbsp; cout &amp;lt;&amp;lt; Add(d1, d2) &amp;lt;&amp;lt; endl;&lt;/p&gt;&lt;p&gt;&amp;nbsp; ^&lt;/p&gt;&lt;p&gt;05_template.cpp:5:20: error: ‘Add’ was not declared in this scope&lt;/p&gt;&lt;p&gt;&amp;nbsp; cout &amp;lt;&amp;lt; Add(d1, d2) &amp;lt;&amp;lt; endl;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^&lt;/p&gt;&lt;p&gt;05_template.cpp:5:25: error: ‘endl’ was not declared in this scope&lt;/p&gt;&lt;p&gt;&amp;nbsp; cout &amp;lt;&amp;lt; Add(d1, d2) &amp;lt;&amp;lt; endl;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;I&amp;#39;m obviously missing something in the tutorial but can&amp;#39;t quite see it&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=15567&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: C++ Tutorial - Templates</title><link>https://community.element14.com/technologies/code_exchange/b/blog/posts/c-tutorial---templates</link><pubDate>Thu, 23 Apr 2015 05:18:43 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:75f6caa6-c8b3-40dd-82b5-101daa689541</guid><dc:creator>Former Member</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Very nice.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=15567&amp;AppID=74&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>