<?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[Problem mit Template-Klasse]]></title><description><![CDATA[<p>Hallo,<br />
ich versuche eine Klasse Becher als Template zu programmieren</p>
<p>Was bedeutet die Fehlermeldung des Compilers:<br />
C2955 &quot;Für die Verwendung der template-Klasse ist eine template-Argumentliste erforderlich.&quot;</p>
<p>Ich verwende Visual C++ 2008 Express<br />
Es ist eine Konsolenanwendung</p>
<pre><code>///////////////////// Becher.h /////////////////////////////
#pragma once
#include &lt;string&gt;
#include &lt;iostream&gt;

template&lt;typename Typ&gt;
class Becher
{
private:
   std::string inhalt;
   Typ fassungsvermoegen;
   float fuellhoehe;
public:
   typedef float AbsWertTyp;
   Becher(std::string i, Typ fa, float fu);      //Konstruktor
   void ausgabe() const {std::cout &lt;&lt; &quot;in Klasse Becher!&quot;;}
   bool reichtKapazitaet(int) const;
   bool reichtKapazitaet(const Becher* b) const;
   static AbsWertTyp berechneAbsolutwert(float gw, float ps);
   int getFuellmenge();
   std::string getInhalt() const { return(inhalt); }
};

//////  Becher.cpp  //////////////////////////////////////////

#include &quot;StdAfx.h&quot;
#include &quot;Becher.h&quot;
#include &lt;iostream&gt;

using namespace std;

/////// An dieser Stelle bringt der Compiler folgenden Fehler:
////// C2955 &quot;Für die Verwendung der template-Klasse ist eine template-Argumentliste erforderlich.&quot;
Becher::Becher(string i, Typ fa, float fu)
: inhalt(i), fassungsvermoegen(fa), fuellhoehe(fu)
{
   if(fa&lt;0)
      throw string(&quot;Negatives Fassungsvermoegen&quot;);
   if(fu&lt;0)
      throw string(&quot;Negative Fuellmenge&quot;);
   if(fu&gt;100)
      throw fu;
}

bool Becher::reichtKapazitaet(int ml) const
{
   float platz = berechneAbsolutwert(
                  static_cast&lt;float&gt;(fassungsvermoegen),
                  100-fuellhoehe);
   return(platz &gt;= ml);
}

bool Becher::reichtKapazitaet(const Becher* b) const 
{
   if(inhalt!=b-&gt;inhalt)
      return(false);
   return(reichtKapazitaet(
      static_cast&lt;int&gt;(berechneAbsolutwert(
                    static_cast&lt;float&gt;(b-&gt;fassungsvermoegen),
                    b-&gt;fuellhoehe))));
}

Becher::AbsWertTyp Becher::berechneAbsolutwert(float gw,
                                  float ps) 
{
   return(static_cast&lt;AbsWertTyp&gt;(gw*ps/100.0F));
}

int Becher::getFuellmenge()
{
   return(static_cast&lt;int&gt;(fassungsvermoegen*fuellhoehe/100.0F));
}

////////// Main.cpp  ///////////////////////////////////////

#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &quot;Becher.h&quot;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
   Becher&lt;int&gt; b(&quot;Milch&quot;, 500, 50);
   b.ausgabe();
	return 0;
}
</code></pre>
<p>Wer kann mir weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325002/problem-mit-template-klasse</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 14:44:52 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325002.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Apr 2014 18:00:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit Template-Klasse on Thu, 10 Apr 2014 18:00:36 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich versuche eine Klasse Becher als Template zu programmieren</p>
<p>Was bedeutet die Fehlermeldung des Compilers:<br />
C2955 &quot;Für die Verwendung der template-Klasse ist eine template-Argumentliste erforderlich.&quot;</p>
<p>Ich verwende Visual C++ 2008 Express<br />
Es ist eine Konsolenanwendung</p>
<pre><code>///////////////////// Becher.h /////////////////////////////
#pragma once
#include &lt;string&gt;
#include &lt;iostream&gt;

template&lt;typename Typ&gt;
class Becher
{
private:
   std::string inhalt;
   Typ fassungsvermoegen;
   float fuellhoehe;
public:
   typedef float AbsWertTyp;
   Becher(std::string i, Typ fa, float fu);      //Konstruktor
   void ausgabe() const {std::cout &lt;&lt; &quot;in Klasse Becher!&quot;;}
   bool reichtKapazitaet(int) const;
   bool reichtKapazitaet(const Becher* b) const;
   static AbsWertTyp berechneAbsolutwert(float gw, float ps);
   int getFuellmenge();
   std::string getInhalt() const { return(inhalt); }
};

//////  Becher.cpp  //////////////////////////////////////////

#include &quot;StdAfx.h&quot;
#include &quot;Becher.h&quot;
#include &lt;iostream&gt;

using namespace std;

/////// An dieser Stelle bringt der Compiler folgenden Fehler:
////// C2955 &quot;Für die Verwendung der template-Klasse ist eine template-Argumentliste erforderlich.&quot;
Becher::Becher(string i, Typ fa, float fu)
: inhalt(i), fassungsvermoegen(fa), fuellhoehe(fu)
{
   if(fa&lt;0)
      throw string(&quot;Negatives Fassungsvermoegen&quot;);
   if(fu&lt;0)
      throw string(&quot;Negative Fuellmenge&quot;);
   if(fu&gt;100)
      throw fu;
}

bool Becher::reichtKapazitaet(int ml) const
{
   float platz = berechneAbsolutwert(
                  static_cast&lt;float&gt;(fassungsvermoegen),
                  100-fuellhoehe);
   return(platz &gt;= ml);
}

bool Becher::reichtKapazitaet(const Becher* b) const 
{
   if(inhalt!=b-&gt;inhalt)
      return(false);
   return(reichtKapazitaet(
      static_cast&lt;int&gt;(berechneAbsolutwert(
                    static_cast&lt;float&gt;(b-&gt;fassungsvermoegen),
                    b-&gt;fuellhoehe))));
}

Becher::AbsWertTyp Becher::berechneAbsolutwert(float gw,
                                  float ps) 
{
   return(static_cast&lt;AbsWertTyp&gt;(gw*ps/100.0F));
}

int Becher::getFuellmenge()
{
   return(static_cast&lt;int&gt;(fassungsvermoegen*fuellhoehe/100.0F));
}

////////// Main.cpp  ///////////////////////////////////////

#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &quot;Becher.h&quot;
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
   Becher&lt;int&gt; b(&quot;Milch&quot;, 500, 50);
   b.ausgabe();
	return 0;
}
</code></pre>
<p>Wer kann mir weiterhelfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393895</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393895</guid><dc:creator><![CDATA[chicken25]]></dc:creator><pubDate>Thu, 10 Apr 2014 18:00:36 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Template-Klasse on Wed, 16 Apr 2014 20:56:14 GMT]]></title><description><![CDATA[<p>Du musst Template-Klassen dort definieren, wo du sie auch deklarierst (in deinem Fall im Header &quot;Becher.h&quot;).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394947</guid><dc:creator><![CDATA[JulianH]]></dc:creator><pubDate>Wed, 16 Apr 2014 20:56:14 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Template-Klasse on Thu, 17 Apr 2014 06:23:13 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/u100590" rel="nofollow">Martin Richter</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/f1" rel="nofollow">MFC (Visual C++)</a> in das Forum <a href="http://www.c-plusplus.net/forum/f15" rel="nofollow">C++ (auch C++0x und C++11)</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394966</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394966</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Thu, 17 Apr 2014 06:23:13 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Template-Klasse on Thu, 17 Apr 2014 09:58:50 GMT]]></title><description><![CDATA[<p>Die eigentliche Fehlermeldung besagt, daß du vor jede Definition der Funktion noch</p>
<pre><code class="language-cpp">template&lt;typename Typ&gt;
</code></pre>
<p>schreiben mußt (sofern du sie außerhalb der Klassendefinition schreibst).</p>
<p>Aber wichtig ist auch der Hinweis von Mr.Long.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394979</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394979</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Thu, 17 Apr 2014 09:58:50 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit Template-Klasse on Thu, 17 Apr 2014 09:29:50 GMT]]></title><description><![CDATA[<p>Th69 schrieb:</p>
<blockquote>
<p>Die eigentliche Fehlermeldung besagt, daß du vor [u]jede[(u] Definition der Funktion noch</p>
<pre><code class="language-cpp">template&lt;typename Typ&gt;
</code></pre>
<p>schreiben mußt (sofern du sie außerhalb der Klassendefinition schreibst).</p>
</blockquote>
<p>Und außerdem dann noch Becher&lt;Typ&gt;:: anstatt Becher::.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394995</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394995</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Thu, 17 Apr 2014 09:29:50 GMT</pubDate></item></channel></rss>