<?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[Pointer und Kopie]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Bib zu Verfügung, die einige Vorgaben hat, wie das typedef (siehe unten). Ich möchte aus einer Fkt. ein Objekt (möglichst mit wenig Kopien) an den cellPtrPtr übergeben bzw. wiederrum in sich speichern. Ich habe versucht das Schema zu skizzieren. Ich hoffe es wird klar, was das soll! Ich sehe vor lauter Pointern nicht mehr durch...bitte um Hilfe! Die Zeile mit der ich nicht klar komme ist markiert.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class cell { 

public : 

cell input();

private :

int index;

};

static cell list;
typedef cell* cellPtr; // muss so bleiben

cell cell::inputExo( ) { list.index=2000; return ( &amp;list ); }

int main() {

cellPtr* cellPtrPtr; // ist vorgegeben und muss bleiben!

cellPtrPtr = new cellPtr[3]; // 3 ist beliebig

cell* myPtr; // kann geändert werden

cellPtrPtr[0] = myPtr-&gt;inputExo(); // wie geht das???

}
</code></pre>
<p>Danke schon mal,<br />
Jo</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/192114/pointer-und-kopie</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 07:59:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/192114.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Sep 2007 16:45:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Pointer und Kopie on Mon, 10 Sep 2007 16:45:12 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe ein Bib zu Verfügung, die einige Vorgaben hat, wie das typedef (siehe unten). Ich möchte aus einer Fkt. ein Objekt (möglichst mit wenig Kopien) an den cellPtrPtr übergeben bzw. wiederrum in sich speichern. Ich habe versucht das Schema zu skizzieren. Ich hoffe es wird klar, was das soll! Ich sehe vor lauter Pointern nicht mehr durch...bitte um Hilfe! Die Zeile mit der ich nicht klar komme ist markiert.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class cell { 

public : 

cell input();

private :

int index;

};

static cell list;
typedef cell* cellPtr; // muss so bleiben

cell cell::inputExo( ) { list.index=2000; return ( &amp;list ); }

int main() {

cellPtr* cellPtrPtr; // ist vorgegeben und muss bleiben!

cellPtrPtr = new cellPtr[3]; // 3 ist beliebig

cell* myPtr; // kann geändert werden

cellPtrPtr[0] = myPtr-&gt;inputExo(); // wie geht das???

}
</code></pre>
<p>Danke schon mal,<br />
Jo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362749</guid><dc:creator><![CDATA[NoPanic2007]]></dc:creator><pubDate>Mon, 10 Sep 2007 16:45:12 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer und Kopie on Mon, 10 Sep 2007 17:14:28 GMT]]></title><description><![CDATA[<p>Lass cell::input einen cellPtr zurückgeben. (Nebenbei: myPtr muss auf ein Objekt zeigen, bevor du eine Methode aufrufen kannst. Und du hast einmal input deklariert aber inputExo definiert).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1362765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362765</guid><dc:creator><![CDATA[this-*gt*that]]></dc:creator><pubDate>Mon, 10 Sep 2007 17:14:28 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer und Kopie on Mon, 10 Sep 2007 19:26:59 GMT]]></title><description><![CDATA[<p>Also wie ich das jetzt verstanden habe, dann etwa so. Nur bekommen ich jetzt ein Speicherzugriffsfehler!?</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class cell { 

public : 

cell* inputExo();
private :

int index;

};

typedef cell* cellPtr;
static cellPtr list;

cell* cell::inputExo( ) { list-&gt;index=2000; return ( list ); }

int main() {

cellPtr* cellPtrPtr; // ist vorgegeben und sollte bleiben!

cellPtrPtr = new cellPtr[3];

cell* myPtr = 0;
cell mycell;

myPtr = &amp;mycell;

cellPtrPtr[0] = myPtr-&gt;inputExo();

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1362841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1362841</guid><dc:creator><![CDATA[NoPanic2007]]></dc:creator><pubDate>Mon, 10 Sep 2007 19:26:59 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer und Kopie on Tue, 11 Sep 2007 09:06:58 GMT]]></title><description><![CDATA[<p>wenn ich valgrind mache, dann kommt sowas:</p>
<p>valgrind --show-reachable=yes ./fun -v<br />
==5395== Memcheck, a memory error detector.<br />
==5395== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.<br />
==5395== Using LibVEX rev 1658, a library for dynamic binary translation.<br />
==5395== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.<br />
==5395== Using valgrind-3.2.2.SVN, a dynamic binary instrumentation framework.<br />
==5395== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.<br />
==5395== For more details, rerun with: -v<br />
==5395==<br />
==5395== Invalid write of size 4<br />
==5395== at 0x4008D7: cell::input() (in /home/jo/project/exodustest/fun)<br />
==5395== by 0x400978: main (in /home/jo/project/exodustest/fun)<br />
==5395== Address 0x0 is not stack'd, malloc'd or (recently) free'd<br />
==5395==<br />
==5395== Process terminating with default action of signal 11 (SIGSEGV)<br />
==5395== Access not within mapped region at address 0x0<br />
==5395== at 0x4008D7: cell::input() (in /home/jo/project/exodustest/fun)<br />
==5395== by 0x400978: main (in /home/jo/project/exodustest/fun)<br />
==5395==<br />
==5395== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 3 from 1)<br />
==5395== malloc/free: in use at exit: 24 bytes in 1 blocks.<br />
==5395== malloc/free: 1 allocs, 0 frees, 24 bytes allocated.<br />
==5395== For counts of detected errors, rerun with: -v<br />
==5395== searching for pointers to 1 not-freed blocks.<br />
==5395== checked 191,632 bytes.<br />
==5395==<br />
==5395== LEAK SUMMARY:<br />
==5395== definitely lost: 0 bytes in 0 blocks.<br />
==5395== possibly lost: 0 bytes in 0 blocks.<br />
==5395== still reachable: 24 bytes in 1 blocks.<br />
==5395== suppressed: 0 bytes in 0 blocks.<br />
Speicherzugriffsfehler</p>
<p>Was jemand wo der Fehler liegt!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1363093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1363093</guid><dc:creator><![CDATA[NoPanic2007]]></dc:creator><pubDate>Tue, 11 Sep 2007 09:06:58 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer und Kopie on Tue, 11 Sep 2007 09:10:31 GMT]]></title><description><![CDATA[<p>NoPanic2007 schrieb:</p>
<blockquote>
<p>==5395== Invalid write of size 4<br />
==5395== at 0x4008D7: cell::input() (in /home/jo/project/exodustest/fun)<br />
==5395== by 0x400978: main (in /home/jo/project/exodustest/fun)<br />
==5395== Address 0x0 is not stack'd, malloc'd or (recently) free'd</p>
</blockquote>
<p>Compilier und Linke mal mit -g, dann kommt in der zweiten Zeile bestimmt &quot;(in xyz.cpp:17)&quot;. Ich nehme mal an Du weist dem cellPtr namens list nirgendwo eine gültige Adresse zu?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1363098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1363098</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Tue, 11 Sep 2007 09:10:31 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer und Kopie on Tue, 11 Sep 2007 09:21:51 GMT]]></title><description><![CDATA[<p>NoPanic2007 schrieb:</p>
<blockquote>
<p>...</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

class cell { 
public : 
   cell* inputExo();
private :
   int index;
};

typedef cell* cellPtr;
static cellPtr list;

cell* cell::inputExo( ) { list-&gt;index=2000; return ( list ); }

int main() {
   cellPtr* cellPtrPtr; // ist vorgegeben und sollte bleiben!
   cellPtrPtr = new cellPtr[3];

   cell* myPtr = 0;
   cell mycell;

   myPtr = &amp;mycell;

   cellPtrPtr[0] = myPtr-&gt;inputExo();

}
</code></pre>
</blockquote>
<p>&quot;list&quot; ist ein Zeiger, der <em>wohin</em> zeigt ?<br />
Anders ausgedrückt: Wellches &quot;cell-Objekt&quot; soll bei dieser Anweisung verändert werden:</p>
<pre><code class="language-cpp">list-&gt;index=2000;
</code></pre>
<p>??</p>
<p>Und schonmal für später: Wo &quot;delete&quot;st Du den mit new angeforderten Speicher ?</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1363099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1363099</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Tue, 11 Sep 2007 09:21:51 GMT</pubDate></item><item><title><![CDATA[Reply to Pointer und Kopie on Tue, 11 Sep 2007 11:26:18 GMT]]></title><description><![CDATA[<p>Ah okay,ich glaub, jetzt funktioniert es! Jetzt ist einiges klar geworden.<br />
Danke!</p>
<p>Am Ende mach ich noch:</p>
<p>delete [] cellPtrPtr;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1363208</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1363208</guid><dc:creator><![CDATA[NoPanic2007]]></dc:creator><pubDate>Tue, 11 Sep 2007 11:26:18 GMT</pubDate></item></channel></rss>