<?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[Arbeiten in Klasse, was mache ich hier falsch?]]></title><description><![CDATA[<p>Moin Leute,<br />
Kann sich vlt jemand mal diesen Programm-Code angugen?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; //Standard Input Output Stream

using namespace std;

class klasse
	{
	char feld [11][11] = {
										   {' ','A','B','C','D','E','F','G','H','I','J'},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
								};
		public:
		void Show()
		{
			int i,j;
			for(i=0;i&lt;=11;i++)
				{
					for (j=0;j&lt;=11;j++)
						{
							cout &lt;&lt; feld[i][j] &lt;&lt; endl;
						}
				}
		}
	};

int main(int argc, char *argv[]) //Hauptprogramm

	{
		klasse klasse_1;
		klasse_1.Show();

     return 0;

	}
</code></pre>
<p>was ist hier Falsch? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":-/"
      alt="😕"
    /> mein Compiler (g++) spuckt volgende Fehler aus:</p>
<pre><code>blub2.cpp:15: error: a brace-enclosed initializer is not allowed here before ‘{’ token
blub2.cpp:27: error: ISO C++ forbids initialization of member ‘feld’
blub2.cpp:27: error: making ‘feld’ static
blub2.cpp:27: error: invalid in-class initialization of static data member of non-integral type ‘char [11][11]’
blub2.cpp: In member function ‘void klasse::Show()’:
blub2.cpp:36: error: ‘feld’ was not declared in this scope
</code></pre>
<p>mfg black Sheep007</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/178753/arbeiten-in-klasse-was-mache-ich-hier-falsch</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 03:19:04 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/178753.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 14 Apr 2007 11:26:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sat, 14 Apr 2007 11:26:50 GMT]]></title><description><![CDATA[<p>Moin Leute,<br />
Kann sich vlt jemand mal diesen Programm-Code angugen?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt; //Standard Input Output Stream

using namespace std;

class klasse
	{
	char feld [11][11] = {
										   {' ','A','B','C','D','E','F','G','H','I','J'},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
								};
		public:
		void Show()
		{
			int i,j;
			for(i=0;i&lt;=11;i++)
				{
					for (j=0;j&lt;=11;j++)
						{
							cout &lt;&lt; feld[i][j] &lt;&lt; endl;
						}
				}
		}
	};

int main(int argc, char *argv[]) //Hauptprogramm

	{
		klasse klasse_1;
		klasse_1.Show();

     return 0;

	}
</code></pre>
<p>was ist hier Falsch? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":-/"
      alt="😕"
    /> mein Compiler (g++) spuckt volgende Fehler aus:</p>
<pre><code>blub2.cpp:15: error: a brace-enclosed initializer is not allowed here before ‘{’ token
blub2.cpp:27: error: ISO C++ forbids initialization of member ‘feld’
blub2.cpp:27: error: making ‘feld’ static
blub2.cpp:27: error: invalid in-class initialization of static data member of non-integral type ‘char [11][11]’
blub2.cpp: In member function ‘void klasse::Show()’:
blub2.cpp:36: error: ‘feld’ was not declared in this scope
</code></pre>
<p>mfg black Sheep007</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1265868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1265868</guid><dc:creator><![CDATA[black Sheep007]]></dc:creator><pubDate>Sat, 14 Apr 2007 11:26:50 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sat, 14 Apr 2007 11:29:25 GMT]]></title><description><![CDATA[<p>Du kannst feld nicht direkt etwas zuweisen. Das mußte dann schon im Konstuktor erledigen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1265869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1265869</guid><dc:creator><![CDATA[Jester]]></dc:creator><pubDate>Sat, 14 Apr 2007 11:29:25 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sat, 14 Apr 2007 11:36:26 GMT]]></title><description><![CDATA[<p>Oder du machst dein Array statisch:</p>
<pre><code class="language-cpp">class klasse
{
	static char feld [11][11];
public:
	void Show()
	{
		int i,j;
		for(i=0;i&lt;=11;i++)
		{
			for (j=0;j&lt;=11;j++)
			{
				std::cout &lt;&lt; feld[i][j] &lt;&lt; std::endl;
			}
		}
	}
}; 

char klasse::feld[11][11] = {
	{' ','A','B','C','D','E','F','G','H','I','J'},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
	{' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1265873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1265873</guid><dc:creator><![CDATA[David_pb]]></dc:creator><pubDate>Sat, 14 Apr 2007 11:36:26 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sat, 14 Apr 2007 11:47:37 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">for(i=0;i&lt;=11;i++)
</code></pre>
<p>0 1 2 3 4 5 6 7 8 9 10 11<br />
...sind insgesamt 12 indices, und du hast ein 11x11 array. Hier wirds krachen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1265877</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1265877</guid><dc:creator><![CDATA[Andrey]]></dc:creator><pubDate>Sat, 14 Apr 2007 11:47:37 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sat, 14 Apr 2007 13:22:59 GMT]]></title><description><![CDATA[<p>Mhn was hat das denn mit den Konstuktoren auf sich?<br />
Fange gerade mit der OOP-Programmierung an <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="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1265927</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1265927</guid><dc:creator><![CDATA[black Sheep007]]></dc:creator><pubDate>Sat, 14 Apr 2007 13:22:59 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sat, 14 Apr 2007 13:31:35 GMT]]></title><description><![CDATA[<p>Der Konstruktor einer Klasse wird immer aufgerufen, wenn eine Instanz der Klasse erzeugt wird. Dort kannst du dann Variablen initialisieren, etc...</p>
<pre><code class="language-cpp">class foo
{
public:
    foo(); //Konstruktor (hat immer den Klassennamen)
private:
    int i; //nur Deklaration der Variable
};

foo::foo()
{
    i = 10; //hier kannste dann einen Wert zuweisen
            //kannst dir auch mal eine &quot;Initialisierungsliste&quot; angucken
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1265928</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1265928</guid><dc:creator><![CDATA[Hazzel]]></dc:creator><pubDate>Sat, 14 Apr 2007 13:31:35 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sun, 15 Apr 2007 13:55:34 GMT]]></title><description><![CDATA[<p>Hazzel schrieb:</p>
<blockquote>
<p>foo::foo()<br />
{<br />
i = 10; //hier kannste dann einen Wert zuweisen<br />
//kannst dir auch mal eine &quot;Initialisierungsliste&quot; angucken<br />
}<br />
[/cpp]</p>
</blockquote>
<p>aber dies kann ich nicht einfach auf ein Array übernehmen oder?<br />
Bei mir spuckt das Programm dann nur wilde Zeichen aus...</p>
<pre><code class="language-cpp">klasse::klasse()
	{
			char feld [11][11]= {
										   {' ','A','B','C','D','E','F','G','H','I','J'},
											{'0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'1',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'2',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'3',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'4',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'5',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'6',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'7',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'8',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
											{'9',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
								};
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1266476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1266476</guid><dc:creator><![CDATA[black Sheep007]]></dc:creator><pubDate>Sun, 15 Apr 2007 13:55:34 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sun, 15 Apr 2007 14:12:00 GMT]]></title><description><![CDATA[<p>so nicht nein. du deklarierst da eine neue variable. lass das char und das [11][11] mal weg, bin aber net sicher ob es dann geht. Wenn nicht musst du das feld einfach durchlaufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1266482</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1266482</guid><dc:creator><![CDATA[Shinja]]></dc:creator><pubDate>Sun, 15 Apr 2007 14:12:00 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Sun, 15 Apr 2007 14:58:27 GMT]]></title><description><![CDATA[<p>Naja ... mal mit dynamischer Größe:</p>
<pre><code class="language-cpp">#if !defined(TEST_CLASS_H__INCLUDED)
#define TEST_CLASS_H__INCLUDED

class test_class
{
public:
	test_class(const size_t&amp;);
	~test_class();

public:
	void	show();

public:
	void	set_item(const size_t&amp;, const size_t&amp;, const char&amp;);
	char	get_item(const size_t&amp;, const size_t&amp;);
	void	set_std_values();

private:
	size_t	m_dimension;
	char**	m_items;
};

#endif // TEST_CLASS_H__INCLUDED
</code></pre>
<pre><code class="language-cpp">#include &quot;test_class.h&quot;

test_class::test_class(const size_t&amp; size) : m_dimension(size)
{
	m_items = new char*[size];
	for (size_t y = 0; y &lt; size; ++y)
		m_items[y] = new char[size];
}

test_class::~test_class()
{
	for (size_t y = 0; y &lt; m_dimension; ++y)
		delete [] m_items[y];

	delete [] m_items;
}

void test_class::show()
{
	for (size_t item = 0; item &lt; m_dimension; ++item)
		std::cout &lt;&lt; m_items[item] &lt;&lt; std::endl;
}

void test_class::set_item(const size_t&amp; x, const size_t&amp; y, const char&amp; c)
{
	if (m_dimension &lt;= x || m_dimension &lt;= y)
		return;

	m_items[x][y] = c;
}

char test_class::get_item(const size_t&amp; x, const size_t&amp; y)
{
	return ((m_dimension &lt;= x || m_dimension &lt;= y) ? 0 : m_items[x][y]);
}

void test_class::set_std_values()
{
	for (size_t y = 0; y &lt; m_dimension; ++y)
		m_items[0][y] = static_cast&lt;char&gt;(y + 65);

	for (size_t x = 1; x &lt; m_dimension; ++x)
	{
		m_items[x][0] = static_cast&lt;char&gt;(x + 47);
		for (size_t y = 1; y &lt; m_dimension; ++y)
			m_items[x][y] = 0;
	}
}
</code></pre>
<pre><code class="language-cpp">int main()
{
	test_class inst(11);
	inst.set_std_values();
	inst.show();
}
</code></pre>
<p><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="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1266502</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1266502</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sun, 15 Apr 2007 14:58:27 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Mon, 16 Apr 2007 14:16:01 GMT]]></title><description><![CDATA[<p>Habs mal überflogen aber so dürfts gehen</p>
<pre><code>[cpp]#include &lt;iostream&gt; //Standard Input Output Stream

using namespace std;

class klasse
    {

        public:
	klasse()//Konstruktor
	{
	feld [0][0] = ' ';
	feld [0][1] = 'A';
	feld [0][2] = 'B';
	feld [0][3] = 'C';
	feld [0][4] = 'D';
	feld [0][5] = 'E';
	feld [0][6] = 'F';
	feld [0][7] = 'G';
	feld [0][8] = 'H';
	feld [0][9] = 'I';
	feld [0][10] = 'J';
	for (int y=1;y&lt;11;++y)
	{
		for (int x=0;x&lt;11;++x)
		{
		feld [y] [x] = ' ';
		}
	}
	}

        void Show()
        {

            for(i=0;i&lt;11;i++)// Vorsicht!! nicht &lt;=(kleinergleich) wenn du ein Feld [11] erstellst 
                //geht dieses von [0 bis 10] und [11] liefert komische Werte
                {

                    for (j=0;j&lt;11;j++)//siehe drüber
                        {
                            cout &lt;&lt; feld[i][j]; /*&lt;&lt; endl; besser runter!!&quot;(soll ja wie ein Feld aussehen ein Feld sein ;))*/
                        }
			cout &lt;&lt; endl;
                }
        }

	private:
//private Variablen der klasse
	    char feld [11] [11]; 
            int i,j;
    };

int main(int argc, char *argv[]) //Hauptprogramm

    {
        klasse klasse_1;//Konstruktoraufruf
        klasse_1.Show();

     return 0;
    }
[/cpp]
</code></pre>
<p>falls du auf Feld auserhalb der Klasse auch zugreifen willst, musst du es in public: reintun</p>
<p>kaffee</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1266642</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1266642</guid><dc:creator><![CDATA[kaffee]]></dc:creator><pubDate>Mon, 16 Apr 2007 14:16:01 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Wed, 18 Apr 2007 13:33:58 GMT]]></title><description><![CDATA[<p>cool <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /> besten Dank<br />
klappt alles bestens</p>
<p>mfg black Sheep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1268479</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1268479</guid><dc:creator><![CDATA[black Sheep007]]></dc:creator><pubDate>Wed, 18 Apr 2007 13:33:58 GMT</pubDate></item><item><title><![CDATA[Reply to Arbeiten in Klasse, was mache ich hier falsch? on Wed, 18 Apr 2007 15:21:36 GMT]]></title><description><![CDATA[<p>(D)Evil schrieb:</p>
<blockquote>
<pre><code class="language-cpp">#if !defined(TEST_CLASS_H__INCLUDED)
</code></pre>
</blockquote>
<p>Warum; wenn's doch</p>
<pre><code class="language-cpp">#ifndef TEST_CLASS_H__INCLUDED
</code></pre>
<p>gibt???<br />
Hast du's einfac so gelernt oder hat das irgentwelche Vorteile???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1268586</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1268586</guid><dc:creator><![CDATA[AGS&#x27;ler]]></dc:creator><pubDate>Wed, 18 Apr 2007 15:21:36 GMT</pubDate></item></channel></rss>