<?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-Default-Argumente]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgenden Quelltext:</p>
<pre><code class="language-cpp">//Basisklasse für Ausnahmen
//Template deswegen, damit man das auch mit Unicode verwenden kann
template&lt;class _CharT = char,class _Traits = std::char_traits&lt;_CharT&gt; &gt;
class Exception
{
  private:
    typedef Exception&lt;_CharT,_Traits&gt; base;
    typedef std::basic_string&lt;_CharT,_Traits&gt; string_type;
    string_type message;
  public:
    Exception() : message() { }
    Exception(const string_type&amp; message) : message(message) { }
    Exception(const base&amp; other) : message(other.message) { }

    virtual const string_type operator () () const { return message; };
    virtual operator string_type() const { return message; };
    virtual const string_type toString() const { return message; };
};
</code></pre>
<p>Damit ich jetzt nicht lästigerweise immer wieder bei Vererbungen die ganzen Konstruktoren usw. mittippen muss, hab ich mir das folgende Makro geschrieben:</p>
<pre><code class="language-cpp">#define EXCEPTION(name,inherited) \
  template&lt;class _CharT = char,class _Traits = std::char_traits&lt;_CharT&gt; &gt; \
  class name : public inherited&lt;_CharT,_Traits&gt; \
  { \
    private: \
      typedef inherited&lt;_CharT,_Traits&gt; base; \
      typedef std::basic_string&lt;_CharT,_Traits&gt; string_type; \
    public: \
      name() : base() { } \
      name(const string_type&amp; message) : base(message) { } \
      name(const base&amp; other) : base(other.message) { } \
  };
</code></pre>
<p>Wenn ich nun an einer anderen Stelle schreibe:</p>
<pre><code class="language-cpp">throw Exception::Size(&quot;Fehler beim Erzeugen einer Matrix: Höhe oder Breite ist 0&quot;);
</code></pre>
<p>...dann gibt es vom MinGW die folgenden Fehler:</p>
<pre><code>&quot;main.cpp&quot;: main.cpp instantiated from here at line 37
&quot;vectorial.hpp&quot;: datatypes/vectorial.hpp no match for call to `(GeoMath::Exception::Size&lt;_CharT, _Traits&gt;) (const char[58])'
 at line 260
</code></pre>
<p>.</p>
<p>Schreibe ich stattdessen</p>
<pre><code class="language-cpp">throw Exception::Size(std::string(&quot;Fehler beim Erzeugen einer Matrix: Höhe oder Breite ist 0&quot;));
</code></pre>
<p>...dann kommt:</p>
<pre><code>&quot;vectorial.hpp&quot;: datatypes/vectorial.hpp no match for call to `(GeoMath::Exception::Size&lt;_CharT, _Traits&gt;) (std::basic_string&lt;char,
std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)' at line 260
</code></pre>
<p>Am Makro liegt es jedenfalls nicht. Wenn ich statt Size Exception einsetze, ist es dasselbe in grün.</p>
<p>Kann sich jemand von euch einen Reim darauf machen? Ich habe den Verdacht, dass das Default-Argument &quot;_CharT = char&quot; nicht berücksichtigt wird.</p>
<p>Danke schonmal.</p>
<p>MfG .crypter</p>
<p>(Der bcc meldet:</p>
<pre><code>&quot;vectorial.hpp&quot;: E2102 Cannot use template 'Exception::Size&lt;_CharT,_Traits&gt;' without specifying specialization parameters in function Matrix&lt;int&gt;::Matrix(const _STL::vector&lt;StaticVector&lt;int&gt;,_STL::allocator&lt;StaticVector&lt;int&gt; &gt; &gt; &amp;) at line 260
</code></pre>
<p>)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/148511/template-default-argumente</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 20:47:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/148511.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 27 May 2006 14:00:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template-Default-Argumente on Sat, 27 May 2006 14:00:53 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgenden Quelltext:</p>
<pre><code class="language-cpp">//Basisklasse für Ausnahmen
//Template deswegen, damit man das auch mit Unicode verwenden kann
template&lt;class _CharT = char,class _Traits = std::char_traits&lt;_CharT&gt; &gt;
class Exception
{
  private:
    typedef Exception&lt;_CharT,_Traits&gt; base;
    typedef std::basic_string&lt;_CharT,_Traits&gt; string_type;
    string_type message;
  public:
    Exception() : message() { }
    Exception(const string_type&amp; message) : message(message) { }
    Exception(const base&amp; other) : message(other.message) { }

    virtual const string_type operator () () const { return message; };
    virtual operator string_type() const { return message; };
    virtual const string_type toString() const { return message; };
};
</code></pre>
<p>Damit ich jetzt nicht lästigerweise immer wieder bei Vererbungen die ganzen Konstruktoren usw. mittippen muss, hab ich mir das folgende Makro geschrieben:</p>
<pre><code class="language-cpp">#define EXCEPTION(name,inherited) \
  template&lt;class _CharT = char,class _Traits = std::char_traits&lt;_CharT&gt; &gt; \
  class name : public inherited&lt;_CharT,_Traits&gt; \
  { \
    private: \
      typedef inherited&lt;_CharT,_Traits&gt; base; \
      typedef std::basic_string&lt;_CharT,_Traits&gt; string_type; \
    public: \
      name() : base() { } \
      name(const string_type&amp; message) : base(message) { } \
      name(const base&amp; other) : base(other.message) { } \
  };
</code></pre>
<p>Wenn ich nun an einer anderen Stelle schreibe:</p>
<pre><code class="language-cpp">throw Exception::Size(&quot;Fehler beim Erzeugen einer Matrix: Höhe oder Breite ist 0&quot;);
</code></pre>
<p>...dann gibt es vom MinGW die folgenden Fehler:</p>
<pre><code>&quot;main.cpp&quot;: main.cpp instantiated from here at line 37
&quot;vectorial.hpp&quot;: datatypes/vectorial.hpp no match for call to `(GeoMath::Exception::Size&lt;_CharT, _Traits&gt;) (const char[58])'
 at line 260
</code></pre>
<p>.</p>
<p>Schreibe ich stattdessen</p>
<pre><code class="language-cpp">throw Exception::Size(std::string(&quot;Fehler beim Erzeugen einer Matrix: Höhe oder Breite ist 0&quot;));
</code></pre>
<p>...dann kommt:</p>
<pre><code>&quot;vectorial.hpp&quot;: datatypes/vectorial.hpp no match for call to `(GeoMath::Exception::Size&lt;_CharT, _Traits&gt;) (std::basic_string&lt;char,
std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)' at line 260
</code></pre>
<p>Am Makro liegt es jedenfalls nicht. Wenn ich statt Size Exception einsetze, ist es dasselbe in grün.</p>
<p>Kann sich jemand von euch einen Reim darauf machen? Ich habe den Verdacht, dass das Default-Argument &quot;_CharT = char&quot; nicht berücksichtigt wird.</p>
<p>Danke schonmal.</p>
<p>MfG .crypter</p>
<p>(Der bcc meldet:</p>
<pre><code>&quot;vectorial.hpp&quot;: E2102 Cannot use template 'Exception::Size&lt;_CharT,_Traits&gt;' without specifying specialization parameters in function Matrix&lt;int&gt;::Matrix(const _STL::vector&lt;StaticVector&lt;int&gt;,_STL::allocator&lt;StaticVector&lt;int&gt; &gt; &gt; &amp;) at line 260
</code></pre>
<p>)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066099</guid><dc:creator><![CDATA[crypter]]></dc:creator><pubDate>Sat, 27 May 2006 14:00:53 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Default-Argumente on Sat, 27 May 2006 14:14:45 GMT]]></title><description><![CDATA[<p>Du benutzt Exception::Size, als ob es eine &quot;normale&quot; Klasse wäre. Um zu zeigen, dass es ein Template ist, gehört noch ein &lt;&gt; hinter Size.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066104</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066104</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Sat, 27 May 2006 14:14:45 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Default-Argumente on Sat, 27 May 2006 14:29:40 GMT]]></title><description><![CDATA[<p>Danke, genau das wars. Ich hab mich jetzt so drumherum gemogelt:</p>
<pre><code class="language-cpp">template&lt;class _CharT,class _Traits = std::char_traits&lt;_CharT&gt; &gt;
    class Basic_Exception
    {
      private:
        typedef Basic_Exception&lt;_CharT,_Traits&gt; base;
        typedef std::basic_string&lt;_CharT,_Traits&gt; string_type;
        string_type message;
      public:
        Basic_Exception() : message() { }
        Basic_Exception(const string_type&amp; message) : message(message) { }
        Basic_Exception(const base&amp; other) : message(other.message) { }

        virtual const string_type operator () () const { return message; };
        virtual operator string_type() const { return message; };
        virtual const string_type toString() const { return message; };
    };

    typedef Basic_Exception&lt;char&gt; Exception;
</code></pre>
<p>So machts die Standardbibliothek schließlich auch.</p>
<p>MfG .crypter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1066115</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1066115</guid><dc:creator><![CDATA[crypter]]></dc:creator><pubDate>Sat, 27 May 2006 14:29:40 GMT</pubDate></item></channel></rss>