<?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[Objekt-Arrays mit CArray]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich habe folgenden Code:</p>
<pre><code class="language-cpp">/******************************************/
class TDatabase: public CDatabase
{
public:
	bool IsInUse();
};

typedef CArray&lt;TDatabase, TDatabase&amp;&gt; cDatabase;

/******************************************/
class ODBC
{
public:
TDatabase *ODBC::GetDatabase()
{
	TDatabase *retDatabase = NULL;
	for (int i = 0; i &lt; this-&gt;pDatabaseArray.GetSize(); i++)
	{
		//get all unused Database connections
		if (!(this-&gt;pDatabaseArray-&gt;GetAt(i)).IsInUse())
		{
			if (retDatabase == NULL)
			{
				retDatabase = this-&gt;pDatabaseArray.GetAt(i);
			}
			else	//delete unused Database connections
			{
				delete &amp;this-&gt;pDatabaseArray.ElementAt(i);
				this-&gt;pDatabaseArray.RemoveAt(i);
			}
		}
	}
	return retDatabase;
}
private:
	cDatabase pDatabaseArray;
};

typedef CArray&lt;ODBC, ODBC&amp;&gt; cODBC;

/******************************************/
class Database
{
	cODBC pODBCArray;
};
</code></pre>
<p>Der Code ist natürlich nicht ganz vollständig, reich taber um mein Problem zu skizzieren:</p>
<p>Meiner Meinung nach sollte das funktionieren, aber denkste, der Compiler schreit beim Übersetzen und ich verstehe nicht ganz warum:</p>
<blockquote>
<p>include\afxtempl.h(255) : error C2558: class 'ODBC' : Kein Kopierkonstruktor verfuegbar<br />
include\afxtempl.h(1566) : Bei der Kompilierung der Member-Funktion 'class ODBC __thiscall CArray&lt;class ODBC,class ODBC &amp;&gt;::GetAt(int) const' der Klassenvorlage</p>
<p>include\afxtempl.h(255) : error C2558: class 'TDatabase' : Kein Kopierkonstruktor verfuegbar<br />
include\afxtempl.h(1566) : Bei der Kompilierung der Member-Funktion 'class TDatabase __thiscall CArray&lt;class TDatabase,class TDatabase &amp;&gt;::GetAt(int) const' der Klassenvorlage</p>
</blockquote>
<p>Wenn ich das TDatabase CArray aus dem ODBC Objekt entferne und einfach nur einen Pointer auf ein TDatabase einbaue funktioniert das ganze ODBC Konstrukt prima. Ich habe nun versucht statt cDatabase pDatabaseArray; cDatabase *pDatabaseArray; zu verwenden, aber dann bekomme ich beim Kompilieren immer noch folgende Fehlermeldung:</p>
<blockquote>
<p>include\afxtempl.h(255) : error C2558: class 'TDatabase' : Kein Kopierkonstruktor verfuegbar<br />
include\afxtempl.h(1566) : Bei der Kompilierung der Member-Funktion 'class TDatabase __thiscall CArray&lt;class TDatabase,class TDatabase &amp;&gt;::GetAt(int) const' der Klassenvorlage</p>
</blockquote>
<p>Wie gesagt, ich verstehe nicht ganz warum der Code nicht kompilierbar ist. Kann mir das jemand erklären und weiss jemand was ich anders machen muss, damit es funktioniert, oder ist das so überhaupt nicht machbar? Danke!</p>
<p>Sebo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/186114/objekt-arrays-mit-carray</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 07:24:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/186114.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Jul 2007 09:41:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Objekt-Arrays mit CArray on Thu, 05 Jul 2007 09:41:53 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Ich habe folgenden Code:</p>
<pre><code class="language-cpp">/******************************************/
class TDatabase: public CDatabase
{
public:
	bool IsInUse();
};

typedef CArray&lt;TDatabase, TDatabase&amp;&gt; cDatabase;

/******************************************/
class ODBC
{
public:
TDatabase *ODBC::GetDatabase()
{
	TDatabase *retDatabase = NULL;
	for (int i = 0; i &lt; this-&gt;pDatabaseArray.GetSize(); i++)
	{
		//get all unused Database connections
		if (!(this-&gt;pDatabaseArray-&gt;GetAt(i)).IsInUse())
		{
			if (retDatabase == NULL)
			{
				retDatabase = this-&gt;pDatabaseArray.GetAt(i);
			}
			else	//delete unused Database connections
			{
				delete &amp;this-&gt;pDatabaseArray.ElementAt(i);
				this-&gt;pDatabaseArray.RemoveAt(i);
			}
		}
	}
	return retDatabase;
}
private:
	cDatabase pDatabaseArray;
};

typedef CArray&lt;ODBC, ODBC&amp;&gt; cODBC;

/******************************************/
class Database
{
	cODBC pODBCArray;
};
</code></pre>
<p>Der Code ist natürlich nicht ganz vollständig, reich taber um mein Problem zu skizzieren:</p>
<p>Meiner Meinung nach sollte das funktionieren, aber denkste, der Compiler schreit beim Übersetzen und ich verstehe nicht ganz warum:</p>
<blockquote>
<p>include\afxtempl.h(255) : error C2558: class 'ODBC' : Kein Kopierkonstruktor verfuegbar<br />
include\afxtempl.h(1566) : Bei der Kompilierung der Member-Funktion 'class ODBC __thiscall CArray&lt;class ODBC,class ODBC &amp;&gt;::GetAt(int) const' der Klassenvorlage</p>
<p>include\afxtempl.h(255) : error C2558: class 'TDatabase' : Kein Kopierkonstruktor verfuegbar<br />
include\afxtempl.h(1566) : Bei der Kompilierung der Member-Funktion 'class TDatabase __thiscall CArray&lt;class TDatabase,class TDatabase &amp;&gt;::GetAt(int) const' der Klassenvorlage</p>
</blockquote>
<p>Wenn ich das TDatabase CArray aus dem ODBC Objekt entferne und einfach nur einen Pointer auf ein TDatabase einbaue funktioniert das ganze ODBC Konstrukt prima. Ich habe nun versucht statt cDatabase pDatabaseArray; cDatabase *pDatabaseArray; zu verwenden, aber dann bekomme ich beim Kompilieren immer noch folgende Fehlermeldung:</p>
<blockquote>
<p>include\afxtempl.h(255) : error C2558: class 'TDatabase' : Kein Kopierkonstruktor verfuegbar<br />
include\afxtempl.h(1566) : Bei der Kompilierung der Member-Funktion 'class TDatabase __thiscall CArray&lt;class TDatabase,class TDatabase &amp;&gt;::GetAt(int) const' der Klassenvorlage</p>
</blockquote>
<p>Wie gesagt, ich verstehe nicht ganz warum der Code nicht kompilierbar ist. Kann mir das jemand erklären und weiss jemand was ich anders machen muss, damit es funktioniert, oder ist das so überhaupt nicht machbar? Danke!</p>
<p>Sebo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318764</guid><dc:creator><![CDATA[SeboStone]]></dc:creator><pubDate>Thu, 05 Jul 2007 09:41:53 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt-Arrays mit CArray on Thu, 05 Jul 2007 09:49:30 GMT]]></title><description><![CDATA[<p>CArray::GetAt() liefert eine Kopie des Array-Elements zurück, aber dazu braucht es den Copy-Ctor - und den liefert TDatabase anscheinend nicht (manche Klassen sind halt nicht kopierbar ;)). Versuch' mal, alle Vorkommen von GetAt() zu ersetzen durch ElementAt() - das liefert eine Referenz und kommt deshalb ohne Copy-Ctor aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318775</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 05 Jul 2007 09:49:30 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt-Arrays mit CArray on Thu, 05 Jul 2007 10:07:08 GMT]]></title><description><![CDATA[<p>Ja das weiss ich. Ich dachte nur, dass ich ElementAt() nur brauche wenn ich schreibend drauf zugreifen will und das mache ich ja. Ich probier's mal schnell aus ..... also ich habe nun alle GetAt() beider CArrays auf ElementAt() umgebaut (suchen-ersetzen), bekomme aber dieselben Fehlermeldungen ..... zweiter Versuch: nun habe ich statt cDatabase pDatabaseArray; cDatabase *pDatabaseArray; verwendet und es kommt nur noch folgender Fehler:</p>
<blockquote>
<p>include\afxtempl.h(255) : error C2558: class 'TDatabase' : Kein Kopierkonstruktor verfuegbar<br />
include\afxtempl.h(1566) : Bei der Kompilierung der Member-Funktion 'class TDatabase __thiscall CArray&lt;class TDatabase,class TDatabase &amp;&gt;::GetAt(int) const' der Klassenvorlage</p>
</blockquote>
<p>Diesen Fehler bekomme ich aber einfach nicht weg - hab' ein bisschen &quot;rumprobiert&quot;. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /> Woran kann es nun noch liegen?</p>
<p>Sebo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318785</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318785</guid><dc:creator><![CDATA[SeboStone]]></dc:creator><pubDate>Thu, 05 Jul 2007 10:07:08 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt-Arrays mit CArray on Thu, 05 Jul 2007 10:17:12 GMT]]></title><description><![CDATA[<p>Du versuchst immer noch etwas nicht-kopierbares in deinem CArray untergebracht, da wird vermutlich jede Methode streiken, die aus irgendeinem Grund Array-Elemente kopieren will (GetAt() ist dafür natürlich der erste Kandidat). Eine Möglichkeit wäre es, deiner Klasse einen eigenen Copy-Ctor zu spendieren (ich bin mir allerdings nicht ganz sicher, ob dessen Basisklasse CDatabase da mitspielt), alternativ kannst du ein CArray&lt;TDatabase*&gt; verwenden (Pointer sind auf jeden Fall kopierbar).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318791</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318791</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 05 Jul 2007 10:17:12 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt-Arrays mit CArray on Thu, 05 Jul 2007 11:00:18 GMT]]></title><description><![CDATA[<p>Einleuchtend, ich weiss nun auch wo das Problem ist, die CArray.Add() Funktion macht intern eine Zuweisung und daran stört sich der Compiler. Ich weiss nur nicht wie ich das ändern soll, ich habe eher den Verdacht, dass das gar nicht geht. Mein Code:</p>
<pre><code class="language-cpp">void ODBC::SetDatabase(TDatabase *value)
{
	this-&gt;pDatabaseArray-&gt;Add(*value);
	this-&gt;pDatabaseArray-&gt;Add(TDatabase::TDatabase());     //funktioniert auch nicht
}
</code></pre>
<p>Jep, es liegt an CDatabase, logischerweise kann es nicht kopiert werden, weil es eine offene Verbindung zu einem DB Server inne haben kann. Test:</p>
<pre><code class="language-cpp">typedef CArray&lt;CDatabase, CDatabase&amp;&gt; cCDatabase;

cCDatabase cdbase;
cdbase.Add(CDatabase::CDatabase());
</code></pre>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p>&gt; selber Fehler, funzt also nicht.</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<p>Also Danke für die Hilfe, jetzt bin ich zwar gefrustet, aber auch schlauer. <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>
<p>Sebo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318833</guid><dc:creator><![CDATA[SeboStone]]></dc:creator><pubDate>Thu, 05 Jul 2007 11:00:18 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt-Arrays mit CArray on Thu, 05 Jul 2007 11:18:33 GMT]]></title><description><![CDATA[<p>Wie ich vorhin schon sagte - verwende doch ein Array von TDatabase-Zeigern (die können kopiert werden, wenn es nötig wird) und kümmere dich selber um die Speicherverwaltung. (alternativ kannst du auch Smart-Pointer ala boost::shared_ptr verwenden)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318850</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318850</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 05 Jul 2007 11:18:33 GMT</pubDate></item><item><title><![CDATA[Reply to Objekt-Arrays mit CArray on Thu, 05 Jul 2007 14:22:47 GMT]]></title><description><![CDATA[<p>Genau das habe ich auch gemacht, hat noch ein paar kleine Anpassungen gebraucht, funzt jezt aber prima. <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="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1318980</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1318980</guid><dc:creator><![CDATA[SeboStone]]></dc:creator><pubDate>Thu, 05 Jul 2007 14:22:47 GMT</pubDate></item></channel></rss>