<?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[Kleiner Fehler bei STL-Container - bitte um schnelle hilfe]]></title><description><![CDATA[<p>Ich habe glaube gerade einen kleinen Denkfehler und komme nicht auf eine idee, was das problem sein könnte.</p>
<p>mein code:</p>
<pre><code>// this vector contains all objects of TStringLanguage
// -&gt; first element: index (identification/name of the languages)
// -&gt; second element: pointer to a language
std::vector&lt;std::pair&lt;std::wstring*,TStringLanguage*&gt; &gt; m_vecLanguages;
</code></pre>
<pre><code>template&lt;class TStringLanguage&gt;
bool db::CStringManager&lt;TStringLanguage&gt;::existLanguage(const std::wstring&amp; _name){
	// loop through the vector (m_vecLanguages)
	std::vector&lt;std::pair&lt;std::wstring*,TStringLanguage*&gt; &gt;::iterator i;
	for(i = m_vecLanguages.begin(); i != m_vecLanguages.end(); ++i) {
		// test whether the element has the given name
		if( std::wstring( (*i).first ).c_str() == _name.c_str() ){
			// element found -&gt; return true
			return true;
		}
	}

	// no element with this name -&gt; return false
	return false;
}
</code></pre>
<p>er gibt mir folgenden fehler aus:</p>
<blockquote>
<p>1&gt; main.cpp<br />
1&gt;f:\stringmanager\stringmanager\cstringmanager.h(191): error C2440: '&lt;function-style-cast&gt;': 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; ' kann nicht in 'std::wstring' konvertiert werden<br />
1&gt; with<br />
1&gt; [<br />
1&gt; _Elem=wchar_t,<br />
1&gt; _Traits=std::char_traits&lt;wchar_t&gt;,<br />
1&gt; _Ax=std::allocator&lt;wchar_t&gt;<br />
1&gt; ]<br />
1&gt; Quelltyp konnte von keinem Konstruktor angenommen werden, oder die Überladungsauflösung des Konstruktors ist mehrdeutig<br />
1&gt; f:\stringmanager\stringmanager\cstringmanager.h(186): Bei der Kompilierung der Klassen-template der bool db::CStringManager&lt;TStringLanguage&gt;::existLanguage(const std::wstring &amp;)-Memberfunktion<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TStringLanguage=db::CStringLanguage<br />
1&gt; ]<br />
1&gt; f:\stringmanager\stringmanager\cstringmanager.h(71): Bei der Kompilierung der Klassen-template der db::CStringManager&lt;TStringLanguage&gt;::CStringManager(void)-Memberfunktion<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TStringLanguage=db::CStringLanguage<br />
1&gt; ]<br />
1&gt; f:\stringmanager\stringmanager\main.cpp(8): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template &quot;db::CStringManager&lt;TStringLanguage&gt;&quot;.<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TStringLanguage=db::CStringLanguage<br />
1&gt; ]<br />
1&gt;f:\stringmanager\stringmanager\cstringmanager.h(191): error C2228: Links von &quot;.c_str&quot; muss sich eine Klasse/Struktur/Union befinden.</p>
</blockquote>
<p>PS: bitte keine Lösung mit C++11 <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> macht ich immer neidisch weil mein compiler das nicht kann (sollte echt mal wechseln)</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/312062/kleiner-fehler-bei-stl-container-bitte-um-schnelle-hilfe</link><generator>RSS for Node</generator><lastBuildDate>Mon, 03 Aug 2026 03:49:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/312062.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Dec 2012 21:21:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 21:23:00 GMT]]></title><description><![CDATA[<p>Ich habe glaube gerade einen kleinen Denkfehler und komme nicht auf eine idee, was das problem sein könnte.</p>
<p>mein code:</p>
<pre><code>// this vector contains all objects of TStringLanguage
// -&gt; first element: index (identification/name of the languages)
// -&gt; second element: pointer to a language
std::vector&lt;std::pair&lt;std::wstring*,TStringLanguage*&gt; &gt; m_vecLanguages;
</code></pre>
<pre><code>template&lt;class TStringLanguage&gt;
bool db::CStringManager&lt;TStringLanguage&gt;::existLanguage(const std::wstring&amp; _name){
	// loop through the vector (m_vecLanguages)
	std::vector&lt;std::pair&lt;std::wstring*,TStringLanguage*&gt; &gt;::iterator i;
	for(i = m_vecLanguages.begin(); i != m_vecLanguages.end(); ++i) {
		// test whether the element has the given name
		if( std::wstring( (*i).first ).c_str() == _name.c_str() ){
			// element found -&gt; return true
			return true;
		}
	}

	// no element with this name -&gt; return false
	return false;
}
</code></pre>
<p>er gibt mir folgenden fehler aus:</p>
<blockquote>
<p>1&gt; main.cpp<br />
1&gt;f:\stringmanager\stringmanager\cstringmanager.h(191): error C2440: '&lt;function-style-cast&gt;': 'std::basic_string&lt;_Elem,_Traits,_Ax&gt; ' kann nicht in 'std::wstring' konvertiert werden<br />
1&gt; with<br />
1&gt; [<br />
1&gt; _Elem=wchar_t,<br />
1&gt; _Traits=std::char_traits&lt;wchar_t&gt;,<br />
1&gt; _Ax=std::allocator&lt;wchar_t&gt;<br />
1&gt; ]<br />
1&gt; Quelltyp konnte von keinem Konstruktor angenommen werden, oder die Überladungsauflösung des Konstruktors ist mehrdeutig<br />
1&gt; f:\stringmanager\stringmanager\cstringmanager.h(186): Bei der Kompilierung der Klassen-template der bool db::CStringManager&lt;TStringLanguage&gt;::existLanguage(const std::wstring &amp;)-Memberfunktion<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TStringLanguage=db::CStringLanguage<br />
1&gt; ]<br />
1&gt; f:\stringmanager\stringmanager\cstringmanager.h(71): Bei der Kompilierung der Klassen-template der db::CStringManager&lt;TStringLanguage&gt;::CStringManager(void)-Memberfunktion<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TStringLanguage=db::CStringLanguage<br />
1&gt; ]<br />
1&gt; f:\stringmanager\stringmanager\main.cpp(8): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template &quot;db::CStringManager&lt;TStringLanguage&gt;&quot;.<br />
1&gt; with<br />
1&gt; [<br />
1&gt; TStringLanguage=db::CStringLanguage<br />
1&gt; ]<br />
1&gt;f:\stringmanager\stringmanager\cstringmanager.h(191): error C2228: Links von &quot;.c_str&quot; muss sich eine Klasse/Struktur/Union befinden.</p>
</blockquote>
<p>PS: bitte keine Lösung mit C++11 <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> macht ich immer neidisch weil mein compiler das nicht kann (sollte echt mal wechseln)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2282520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282520</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Sat, 22 Dec 2012 21:23:00 GMT</pubDate></item><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 21:24:51 GMT]]></title><description><![CDATA[<blockquote>
<pre><code>std::wstring( (*i).first ).c_str() /// Zeile 7 im obigen Code
</code></pre>
</blockquote>
<p><code>first</code> ist ein Zeiger auf einen <code>wstring</code> , nicht ein <code>wstring</code> selbst.<br />
Mach daraus einfach</p>
<pre><code>i-&gt;first-&gt;c_str()
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2282521</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282521</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 22 Dec 2012 21:24:51 GMT</pubDate></item><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 21:27:22 GMT]]></title><description><![CDATA[<blockquote>
<p>PS: bitte keine Lösung mit C++11</p>
</blockquote>
<p>Tjo, mit Lambdas und <code>std::find_if</code> wäre das schon schöner :p</p>
<p>Edit: <strong>Du hast da einen schlimmen Fehler! Du kannst doch nicht zwei C-Strings mit <code>==</code> vergleichen!</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2282522</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282522</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 22 Dec 2012 21:27:22 GMT</pubDate></item><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 21:55:34 GMT]]></title><description><![CDATA[<p>Wovon ich spreche:</p>
<pre><code>if( std::wstring( (*i).first ).c_str() == _name.c_str() )
</code></pre>
<p>Ganz schlechte Idee!<br />
Mach lieber</p>
<pre><code>if( (*i-&gt;first) == _name )
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2282524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282524</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 22 Dec 2012 21:55:34 GMT</pubDate></item><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 21:34:35 GMT]]></title><description><![CDATA[<blockquote>
<p>Du hast da einen schlimmen Fehler! Du kannst doch nicht zwei C-Strings mit == vergleichen!</p>
</blockquote>
<p>Ach du Sche***, das hab ich in meinem halben projekt so gemacht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":O"
      alt="😮"
    /> (gut das ich noch nicht soweit bin).<br />
Hatte aber bisher komischerweise noch keine Fehler.</p>
<blockquote>
<p>(*i-&gt;first) == _name</p>
</blockquote>
<p>scheint zu funktionieren <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2282525</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282525</guid><dc:creator><![CDATA[gamer8o4]]></dc:creator><pubDate>Sat, 22 Dec 2012 21:34:35 GMT</pubDate></item><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 21:55:29 GMT]]></title><description><![CDATA[<p>Weshalb hast du überhaupt Pointer? Warum nicht einfach <code>std::pair&lt;std::wstring,TStringLanguage&gt;</code> ?<br />
Btw <a href="http://t.co/5U0ETtoH" rel="nofollow">Modern C++</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2282528</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282528</guid><dc:creator><![CDATA[faqir]]></dc:creator><pubDate>Sat, 22 Dec 2012 21:55:29 GMT</pubDate></item><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 21:57:46 GMT]]></title><description><![CDATA[<blockquote>
<p>Hatte aber bisher komischerweise noch keine Fehler.</p>
</blockquote>
<p>Hast du das überhaupt mal getestet?</p>
<blockquote>
<p>faqir schrieb:</p>
<blockquote>
<p>Weshalb hast du überhaupt Pointer? Warum nicht einfach <code>std::pair&lt;std::wstring,TStringLanguage&gt;</code> ?</p>
</blockquote>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2282529</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282529</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 22 Dec 2012 21:57:46 GMT</pubDate></item><item><title><![CDATA[Reply to Kleiner Fehler bei STL-Container - bitte um schnelle hilfe on Sat, 22 Dec 2012 22:10:54 GMT]]></title><description><![CDATA[<p>Um noch etwas weiter zu gehen, warum nicht <code>std::map&lt;std::wstring, TStringLanguage&gt;</code> ?</p>
<p>Dann wird die Funktion zu</p>
<pre><code class="language-cpp">template&lt;class TStringLanguage&gt;
bool db::CStringManager&lt;TStringLanguage&gt;::existLanguage(const std::wstring&amp; _name){
    return m_mapLanguages.count(_name);
}
</code></pre>
<p>Btw^2: Namen, die mit Unterstrichen beginnen, sollte man in C++ vermeiden, weil sie nahe an den reservierten Bezeichnern sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2282530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2282530</guid><dc:creator><![CDATA[faqir]]></dc:creator><pubDate>Sat, 22 Dec 2012 22:10:54 GMT</pubDate></item></channel></rss>