<?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[finde den fehler nicht]]></title><description><![CDATA[<p>Hallo Leute,<br />
ich bin anfänger und wollte ein wenig mit &lt;vector&gt; rumprobieren.<br />
Irgendwie schaffe ich es nicht. Hier ist mein Code:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
...
namespace test{
	std::vector&lt;int&gt; test1;

	test1.push_back(1);
}
...
</code></pre>
<p>Diesen Code kann ich nicht kompilieren. &quot;test1.&quot; wird in VS2010 rot unterlegt und wenn ich darüber mit der Maus fahre kommt als Nachricht kommt folgendes:</p>
<pre><code>Error: this declaration has no storage or type specifier.
</code></pre>
<p>Was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/272275/finde-den-fehler-nicht</link><generator>RSS for Node</generator><lastBuildDate>Fri, 28 Aug 2026 22:11:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/272275.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Aug 2010 20:16:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to finde den fehler nicht on Fri, 13 Aug 2010 20:16:26 GMT]]></title><description><![CDATA[<p>Hallo Leute,<br />
ich bin anfänger und wollte ein wenig mit &lt;vector&gt; rumprobieren.<br />
Irgendwie schaffe ich es nicht. Hier ist mein Code:</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
...
namespace test{
	std::vector&lt;int&gt; test1;

	test1.push_back(1);
}
...
</code></pre>
<p>Diesen Code kann ich nicht kompilieren. &quot;test1.&quot; wird in VS2010 rot unterlegt und wenn ich darüber mit der Maus fahre kommt als Nachricht kommt folgendes:</p>
<pre><code>Error: this declaration has no storage or type specifier.
</code></pre>
<p>Was mache ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939805</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939805</guid><dc:creator><![CDATA[fehler_]]></dc:creator><pubDate>Fri, 13 Aug 2010 20:16:26 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Fri, 13 Aug 2010 20:20:32 GMT]]></title><description><![CDATA[<p>du kannst in einem namespace nicht direkt code ausfuehren.</p>
<p>probier mal</p>
<pre><code class="language-cli">#include &lt;vector&gt;
#include &lt;stdlib.h&gt;

int main(int argc, char** argv) {
    std::vector&lt;int&gt; test1;

    test1.push_back(1);
    return EXIT_SUCCESS;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1939808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939808</guid><dc:creator><![CDATA[dineki89]]></dc:creator><pubDate>Fri, 13 Aug 2010 20:20:32 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Fri, 13 Aug 2010 20:32:07 GMT]]></title><description><![CDATA[<p>dineki89 schrieb:</p>
<blockquote>
<p>du kannst in einem namespace nicht direkt code ausfuehren</p>
</blockquote>
<p>Danke schonmal fuer die schnelle Hilfe. Also muss das &quot;Tanken&quot; des Vektors innerhalb eines Anweisungsblocks geschehen?</p>
<p>Ich möchte nämlich für mein kleines Programm den Text in einem Vektor zusammenfassen. So in etwa:</p>
<pre><code class="language-cpp">// util.h
...
namespace messages{
 vector&lt;string&gt; text,caption;
}
...
// util.cpp
namespace messages{
 text.push_back(&quot;Text 1&quot;);
 text.push_back(&quot;Text 2&quot;);
....
// identisch mit caption
}
</code></pre>
<p>Jetzt inkludiere ich überall, wo ich etwas ausgebe diese util.h.<br />
Wenn ich eine Messagebox ausgeben will, dann mache ich es einfach mit:</p>
<pre><code class="language-cpp">msgbox(text[0]);
</code></pre>
<p>Das es nicht so funktioniert habe ich nun verstanden.<br />
Kann mir jemand sagen warum es nicht geht und wie man meine Aufgabenstellung geschickter lösen kann?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939811</guid><dc:creator><![CDATA[fehler_]]></dc:creator><pubDate>Fri, 13 Aug 2010 20:32:07 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Fri, 13 Aug 2010 20:37:34 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">namespace messages
{
	static const char * const text[2] =
	{
		&quot;Text 1&quot;, &quot;Text 2&quot;
	};
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1939813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939813</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Fri, 13 Aug 2010 20:37:34 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Sat, 14 Aug 2010 08:28:30 GMT]]></title><description><![CDATA[<p>fehler_ schrieb:</p>
<blockquote>
<pre><code class="language-cpp">// util.cpp
namespace messages{
 text.push_back(&quot;Text 1&quot;);
 text.push_back(&quot;Text 2&quot;);

}
</code></pre>
</blockquote>
<p>Nein, du kannst in einem namespace nicht direkt Code ausführen, wie dir schon gesagt wurde.</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;iostream&gt;

namespace messages
{
  const struct Msg : public std::vector&lt;std::string&gt; 
  { 
    Msg() 
    { 
      push_back( &quot;text1&quot; );
      push_back( &quot;text2&quot; ); 
    }
  } txt;
}

int main()
{
  for( messages::Msg::const_iterator it = messages::txt.begin(); it != messages::txt.end(); ++ it ) {
    std::cerr &lt;&lt; *it &lt;&lt; &quot;\n&quot;;
  }
}
</code></pre>
<p>So kannst du es machen.</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939892</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 14 Aug 2010 08:28:30 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Sat, 14 Aug 2010 08:39:42 GMT]]></title><description><![CDATA[<p>Was hier alles für ein Müll vorgeschlagen wird. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939897</guid><dc:creator><![CDATA[bitteNicht]]></dc:creator><pubDate>Sat, 14 Aug 2010 08:39:42 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Sat, 14 Aug 2010 08:50:58 GMT]]></title><description><![CDATA[<p>Das von manni66 war in der Tat schlecht. Bitte nicht so rumerben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939900</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939900</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 14 Aug 2010 08:50:58 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Sat, 14 Aug 2010 09:10:40 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Das von manni66 war in der Tat schlecht. Bitte nicht so rumerben.</p>
</blockquote>
<p>Nun, das wird ja in dieser allgemeinen Form immer wieder gerne erzählt, ist aber auch genauso falsch. Gefährlich wird es, wenn man so eine Objekt mit new allokiert und dann als vector löscht. Eine Konstante ist aber vollkommen unproblematisch!</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939907</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sat, 14 Aug 2010 09:10:40 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Sat, 14 Aug 2010 09:18:38 GMT]]></title><description><![CDATA[<p>fehler_ schrieb:</p>
<blockquote>
<p>Hallo Leute,<br />
ich bin anfänger und wollte ein wenig mit &lt;vector&gt; rumprobieren.</p>
</blockquote>
<p>fehler_ schrieb:</p>
<blockquote>
<p>Jetzt inkludiere ich überall, wo ich etwas ausgebe diese util.h.<br />
Wenn ich eine Messagebox ausgeben will, dann mache ich es einfach mit:</p>
<pre><code class="language-cpp">msgbox(text[0]);
</code></pre>
<p>Das es nicht so funktioniert habe ich nun verstanden.<br />
Kann mir jemand sagen warum es nicht geht und wie man meine Aufgabenstellung geschickter lösen kann?</p>
</blockquote>
<p>Versuch doch mal eine sinnvolle Aufgabenstellung für vectoren und nicht sowas sinnfreies.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939909</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939909</guid><dc:creator><![CDATA[bitteNicht]]></dc:creator><pubDate>Sat, 14 Aug 2010 09:18:38 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Sat, 14 Aug 2010 09:19:42 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>vollkommen unproblematisch!</p>
</blockquote>
<p>Aber die Vererbung da ist unnötig.<br />
Ich mag TyRoXx' Weg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1939910</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1939910</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 14 Aug 2010 09:19:42 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Sun, 15 Aug 2010 07:47:53 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>manni66 schrieb:</p>
<blockquote>
<p>vollkommen unproblematisch!</p>
</blockquote>
<p>Aber die Vererbung da ist unnötig.<br />
Ich mag TyRoXx' Weg.</p>
</blockquote>
<p>Hm, char* und ein array, das seine Größe nicht kennt und noch nicht einmal einen Endemarker enthält?</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940166</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940166</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 15 Aug 2010 07:47:53 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Mon, 16 Aug 2010 05:03:23 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>Hm, char* und ein array, das seine Größe nicht kennt und noch nicht einmal einen Endemarker enthält?</p>
</blockquote>
<p>Das Array ist vom Typ const char * const (&amp;)[2] und kennt damit seine Größe sehr wohl. Die lässt sich auch zuverlässig ermitteln, hatten wir kürzlich erst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940416</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940416</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 16 Aug 2010 05:03:23 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Mon, 16 Aug 2010 05:15:31 GMT]]></title><description><![CDATA[<p>Vorschlag zur Güte:</p>
<pre><code class="language-cpp">// Header

namespace foo {
  extern std::vector&lt;std::string&gt; const &amp;array;
}

// Source
namespace foo {
  namespace {
    struct array_initializer {
      array_initializer() {
        data.push_back(&quot;Text 1&quot;);
        data.push_back(&quot;Text 2&quot;);
      }

      std::vector&lt;std::string&gt; data;
    };

    array_initializer const init;
  }

  std::vector&lt;std::string&gt; const &amp;array = init.data;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1940418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940418</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Mon, 16 Aug 2010 05:15:31 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Mon, 16 Aug 2010 08:21:44 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>manni66 schrieb:</p>
<blockquote>
<p>Hm, char* und ein array, das seine Größe nicht kennt und noch nicht einmal einen Endemarker enthält?</p>
</blockquote>
<p>Das Array ist vom Typ const char * const (&amp;)[2] und kennt damit seine Größe sehr wohl. Die lässt sich auch zuverlässig ermitteln, hatten wir kürzlich erst.</p>
</blockquote>
<p>Wie ermittelst du die Größe innerhalb einer Funktion, wenn du das Array als Parameter übergeben hast? Hier liegt ein großer Unterschied zu std::vector: der hat eine Funktion size(), die einem die Größe liefert bzw. Iteratoren, die Anfang und Ende festlegen.</p>
<p>Das char* war im Übrigen als Gegensatz zu std::string gemeint. Auch der hat Vorteile gegenüber einem char*, egal ob const oder nicht.</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940467</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 16 Aug 2010 08:21:44 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Mon, 16 Aug 2010 08:29:05 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>LordJaxom schrieb:</p>
<blockquote>
<p>Das Array ist vom Typ const char * const (&amp;)[2] und kennt damit seine Größe sehr wohl. Die lässt sich auch zuverlässig ermitteln, hatten wir kürzlich erst.</p>
</blockquote>
<p>Wie ermittelst du die Größe innerhalb einer Funktion, wenn du das Array als Parameter übergeben hast? Hier liegt ein großer Unterschied zu std::vector: der hat eine Funktion size(), die einem die Größe liefert bzw. Iteratoren, die Anfang und Ende festlegen.</p>
</blockquote>
<p>Das funktioniert dann natürlich nicht mehr, aber das braucht man u.U. garnicht mehr. Ein solches Array kann gut als Initializer o.ä. dienen, wenn man gerade kein Boost oder keine C++0x initializer lists zur Verfügung hat.</p>
<p>Deshalb auch von mir ein Vorschlag zur Güte:</p>
<pre><code class="language-cpp">char const* const arrayInitializer[] = { &quot;Text1&quot;, &quot;Text2&quot;, &quot;Text3&quot; };
std::vector&lt;std::string&gt; const array( arrayInitializer, arrayInitializer + sizeof(arrayInitializer)/sizeof(*arrayInitializer) );
</code></pre>
<p>Sieht zwar nicht schön aus, aber ist m.E. praktikabel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940471</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940471</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Mon, 16 Aug 2010 08:29:05 GMT</pubDate></item><item><title><![CDATA[Reply to finde den fehler nicht on Mon, 16 Aug 2010 08:44:49 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>Deshalb auch von mir ein Vorschlag zur Güte:</p>
<pre><code class="language-cpp">char const* const arrayInitializer[] = { &quot;Text1&quot;, &quot;Text2&quot;, &quot;Text3&quot; };
std::vector&lt;std::string&gt; const array( arrayInitializer, arrayInitializer + sizeof(arrayInitializer)/sizeof(*arrayInitializer) );
</code></pre>
<p>Sieht zwar nicht schön aus, aber ist m.E. praktikabel.</p>
</blockquote>
<p>Ja, wenn man Angst vor einer Ableitung hat, sollte man es so machen.</p>
<p>Lars</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940474</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940474</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Mon, 16 Aug 2010 08:44:49 GMT</pubDate></item></channel></rss>