<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[template-Verständnis]]></title><description><![CDATA[<p>hallo<br />
es wäre sehr nett, wenn mir jemand das folgene Programm kommentiert und ganz besonders die template-Köpfe. vielen Dank</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;string&gt;

template&lt;typename t&gt;
t &amp;read_type_ref(t                 &amp;ref,
                 std::string const &amp;prompt = &quot;&quot;,                   //??
                 std::istream      &amp;in     = std::cin,            //??
                 std::ostream      &amp;out    = std::cout) {         //??
  std::string line;
  std::istringstream sstr;

  do {
    sstr.clear();

    out &lt;&lt; prompt &lt;&lt; std::flush;
    std::getline(in, line);
    sstr.str(line);
    sstr &gt;&gt; ref;
  } while(!sstr);

  return ref;
}

template&lt;&gt;
std::string &amp;read_type_ref&lt;std::string&gt;(std::string        &amp;ref,
                                        std::string  const &amp;prompt,
                                        std::istream       &amp;in,
                                        std::ostream       &amp;out) 
{
  out &lt;&lt; prompt &lt;&lt; std::flush;
  std::getline(in, ref);

  return ref;
}

template&lt;typename t&gt;
t read_type(std::string  const &amp;prompt = &quot;&quot;,
            std::istream       &amp;in     = std::cin,
            std::ostream       &amp;out    = std::cout) 
{
  t ret;
  return read_type_ref(ret, prompt, in, out);
}
int main() 
{
  int x = read_type&lt;int&gt;(&quot;Zahl eingeben: &quot;);
  std::string s;

  std::cout &lt;&lt; read_type_ref(s, &quot;Irgendwas eingeben: &quot;) &lt;&lt; std::endl
            &lt;&lt; x                                        &lt;&lt; std::endl;
  return 0;
}
</code></pre>
<p>was ist der Unterschied genau zwischen die 3 templates?<br />
Danke sehr</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/120523/template-verständnis</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 10:11:22 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/120523.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Sep 2005 08:29:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to template-Verständnis on Wed, 14 Sep 2005 08:29:04 GMT]]></title><description><![CDATA[<p>hallo<br />
es wäre sehr nett, wenn mir jemand das folgene Programm kommentiert und ganz besonders die template-Köpfe. vielen Dank</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;string&gt;

template&lt;typename t&gt;
t &amp;read_type_ref(t                 &amp;ref,
                 std::string const &amp;prompt = &quot;&quot;,                   //??
                 std::istream      &amp;in     = std::cin,            //??
                 std::ostream      &amp;out    = std::cout) {         //??
  std::string line;
  std::istringstream sstr;

  do {
    sstr.clear();

    out &lt;&lt; prompt &lt;&lt; std::flush;
    std::getline(in, line);
    sstr.str(line);
    sstr &gt;&gt; ref;
  } while(!sstr);

  return ref;
}

template&lt;&gt;
std::string &amp;read_type_ref&lt;std::string&gt;(std::string        &amp;ref,
                                        std::string  const &amp;prompt,
                                        std::istream       &amp;in,
                                        std::ostream       &amp;out) 
{
  out &lt;&lt; prompt &lt;&lt; std::flush;
  std::getline(in, ref);

  return ref;
}

template&lt;typename t&gt;
t read_type(std::string  const &amp;prompt = &quot;&quot;,
            std::istream       &amp;in     = std::cin,
            std::ostream       &amp;out    = std::cout) 
{
  t ret;
  return read_type_ref(ret, prompt, in, out);
}
int main() 
{
  int x = read_type&lt;int&gt;(&quot;Zahl eingeben: &quot;);
  std::string s;

  std::cout &lt;&lt; read_type_ref(s, &quot;Irgendwas eingeben: &quot;) &lt;&lt; std::endl
            &lt;&lt; x                                        &lt;&lt; std::endl;
  return 0;
}
</code></pre>
<p>was ist der Unterschied genau zwischen die 3 templates?<br />
Danke sehr</p>
]]></description><link>https://www.c-plusplus.net/forum/post/871714</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/871714</guid><dc:creator><![CDATA[lesi19]]></dc:creator><pubDate>Wed, 14 Sep 2005 08:29:04 GMT</pubDate></item><item><title><![CDATA[Reply to template-Verständnis on Wed, 14 Sep 2005 09:12:50 GMT]]></title><description><![CDATA[<p>bei der ersten funkion übergibst du eine refernz in die gelesen wird</p>
<p>zweite ist eine spezialisierung auf std::string siehe <a href="http://www.cpp-tutor.de/cpp/le17/le17_01.htm" rel="nofollow">http://www.cpp-tutor.de/cpp/le17/le17_01.htm</a></p>
<p>bei der dritten funktion wird ein objekt erzeut und die kopie zurückgeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/871749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/871749</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 14 Sep 2005 09:12:50 GMT</pubDate></item><item><title><![CDATA[Reply to template-Verständnis on Wed, 14 Sep 2005 10:21:06 GMT]]></title><description><![CDATA[<p>vielen dank für die Antwort.<br />
könntet ihr vielleicht etwa ausführlicher die templates beschreiben.<br />
vielen dan?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/871800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/871800</guid><dc:creator><![CDATA[lesi19]]></dc:creator><pubDate>Wed, 14 Sep 2005 10:21:06 GMT</pubDate></item><item><title><![CDATA[Reply to template-Verständnis on Wed, 14 Sep 2005 10:28:29 GMT]]></title><description><![CDATA[<p>lesi19 schrieb:</p>
<blockquote>
<p>könntet ihr vielleicht etwa ausführlicher die templates beschreiben.</p>
</blockquote>
<p>was meinst du?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/871810</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/871810</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 14 Sep 2005 10:28:29 GMT</pubDate></item><item><title><![CDATA[Reply to template-Verständnis on Wed, 14 Sep 2005 10:51:24 GMT]]></title><description><![CDATA[<p>Danke miller_m, dass du immer noch dabei bist<br />
ich weiss,dass dies vielleicht eine Nummer groß für mich aber muss es verstehen.<br />
warum in der 1. template die referenz ?<br />
wieso wird das objekt erzeugt? verhält ein Funk_template genauso wie Objekt-erzeugung einer klasse oder bin daneben?<br />
Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/871837</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/871837</guid><dc:creator><![CDATA[lesi19]]></dc:creator><pubDate>Wed, 14 Sep 2005 10:51:24 GMT</pubDate></item><item><title><![CDATA[Reply to template-Verständnis on Wed, 14 Sep 2005 11:05:06 GMT]]></title><description><![CDATA[<p>du solltest dich mal mit der parameterübergabe (by val, by ref, pointer) auseinander setzten dann wird dir dieses eigentlich klar.<br />
oben rechts findest du ein paar tutorials:<br />
bsp:<br />
<a href="http://tutorial.schornboeck.net/referenzen.htm" rel="nofollow">http://tutorial.schornboeck.net/referenzen.htm</a><br />
<a href="http://cplus.kompf.de/artikel/funcpar.html" rel="nofollow">http://cplus.kompf.de/artikel/funcpar.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/871846</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/871846</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 14 Sep 2005 11:05:06 GMT</pubDate></item></channel></rss>