<?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[komme nicht weiter&#x2F;Klassenfehler?]]></title><description><![CDATA[<p>Tach auch,</p>
<p>hoffe dass man mir hier weiterhelfen kann. Ich möchte mir eine Klasse erzeugen in der ich am liebsten ein dynamischen Array von Punkten habe. Momentan habe ich es statisch erzeugt. Problematik dabei ist, dass ich auch ein Array von der Klasse anlegen möchte, denn beide größen (anzahl der Strukturen, sowie anzahl der Punkte in der Struktur) lese ich aus einer Datei.<br />
In meiner Version lese ich die Datei gleich 2x. Zum ersten mal um die anzahl auszulesen und im zweiten Durchlauf wird dann erst richtig eingelesen. Jedoch bekomme ich einen Compiler-fehler, was auch sonst.</p>
<pre><code>///// MAIN 
int main(int argc, char *argv[]) {
...
	error = read_parameter(&amp;numStructures, &amp;maxPoints, &amp;width, &amp;height, argv[1]);

	Elem Structures[numStructures];
	error = read_structures(&amp;Structures, maxPoints, argv[1]);
...
}

///// Function
int read_Structures(Elem **Strukturen, int maxPoints, char *infile){

... /*lese werte ein und merke auf Struktur t */

	(*Strukturen)[structureID] = t;
...
}/* read_structures */

///// Class
class Elem{

	...
private:
	int id;
	char *name;
	int numPnt;
	Pnt *points;
};
</code></pre>
<p>Die Fehlermeldung lautet:<br />
Multiple markers at this line<br />
- cannot convert `Elem (<em>)[((numStructures - 1) + 1)]' to `Elem**' for argument `1' to `int<br />
read_structures(Elem**, int, char</em>)'<br />
- Line breakpoint: Main.cpp</p>
<p>Hoffe ihr habt ne Idee oder alternative Vorschläge</p>
<p>Danke schonmal</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/201649/komme-nicht-weiter-klassenfehler</link><generator>RSS for Node</generator><lastBuildDate>Tue, 06 Oct 2026 05:02:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/201649.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 Jan 2008 15:31:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to komme nicht weiter&#x2F;Klassenfehler? on Wed, 02 Jan 2008 15:31:49 GMT]]></title><description><![CDATA[<p>Tach auch,</p>
<p>hoffe dass man mir hier weiterhelfen kann. Ich möchte mir eine Klasse erzeugen in der ich am liebsten ein dynamischen Array von Punkten habe. Momentan habe ich es statisch erzeugt. Problematik dabei ist, dass ich auch ein Array von der Klasse anlegen möchte, denn beide größen (anzahl der Strukturen, sowie anzahl der Punkte in der Struktur) lese ich aus einer Datei.<br />
In meiner Version lese ich die Datei gleich 2x. Zum ersten mal um die anzahl auszulesen und im zweiten Durchlauf wird dann erst richtig eingelesen. Jedoch bekomme ich einen Compiler-fehler, was auch sonst.</p>
<pre><code>///// MAIN 
int main(int argc, char *argv[]) {
...
	error = read_parameter(&amp;numStructures, &amp;maxPoints, &amp;width, &amp;height, argv[1]);

	Elem Structures[numStructures];
	error = read_structures(&amp;Structures, maxPoints, argv[1]);
...
}

///// Function
int read_Structures(Elem **Strukturen, int maxPoints, char *infile){

... /*lese werte ein und merke auf Struktur t */

	(*Strukturen)[structureID] = t;
...
}/* read_structures */

///// Class
class Elem{

	...
private:
	int id;
	char *name;
	int numPnt;
	Pnt *points;
};
</code></pre>
<p>Die Fehlermeldung lautet:<br />
Multiple markers at this line<br />
- cannot convert `Elem (<em>)[((numStructures - 1) + 1)]' to `Elem**' for argument `1' to `int<br />
read_structures(Elem**, int, char</em>)'<br />
- Line breakpoint: Main.cpp</p>
<p>Hoffe ihr habt ne Idee oder alternative Vorschläge</p>
<p>Danke schonmal</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429400</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429400</guid><dc:creator><![CDATA[Flaut]]></dc:creator><pubDate>Wed, 02 Jan 2008 15:31:49 GMT</pubDate></item><item><title><![CDATA[Reply to komme nicht weiter&#x2F;Klassenfehler? on Wed, 02 Jan 2008 15:44:20 GMT]]></title><description><![CDATA[<p>2 heiße Tipps:</p>
<ol>
<li>Den kompletten Code und Fehlermeldungen mit Zeilenangaben posten.</li>
<li>Klassen, die in main() verwendet werden, müssen vorher bereits bekannt sein.</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/1429412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429412</guid><dc:creator><![CDATA[moagnus]]></dc:creator><pubDate>Wed, 02 Jan 2008 15:44:20 GMT</pubDate></item><item><title><![CDATA[Reply to komme nicht weiter&#x2F;Klassenfehler? on Thu, 03 Jan 2008 11:21:35 GMT]]></title><description><![CDATA[<p>wollte eigentlich nicht den ganzen quellcode zeigen, weil das meiste damit nichts zu tun hat.</p>
<pre><code>#ifndef KLASSEN_H_
#define KLASSEN_H_

#include &lt;string&gt;
using namespace std;

class Pnt{
public:
	Pnt(void){x=0;y=0;}
	Pnt(int i, int j){x=i;y=j;}
	Pnt(const Pnt&amp; rhs){x=rhs.x; y=rhs.y;}
	int get_x(void){return x;}
	int get_y(void){return y;}
	void set_x(int i){x=i;}
	void set_y(int j){y=j;}

private:
	int x;
	int y;
};

class Elem{
public:
	//default constructor
	Elem(void){id=0; name=&quot;&quot;; numPnt=0;}
	//constructor
	Elem(int MAXPNT){numPnt=MAXPNT; create_Pnts(numPnt);}
	//copy constructor
	Elem(const Elem&amp; rhs){id=rhs.id; name=rhs.name; numPnt=rhs.numPnt;}
	//destructor
	~Elem(void){}

	void  set_name(char *NAME){name=NAME;}
	char* get_name(void){return name;}
	void set_id(int ID){id=ID;}
	int  get_id(void){return id;}
	void set_numPoints(int numPoints){numPnt=numPoints;}
	int  get_numPoints(void){return numPnt;}
	void add_pnt(Pnt P, int POS){points[POS]=P;}
	Pnt  get_pnt(int pos){return points[pos];}

private:
	int id;
	char *name;
	int numPnt;
	Pnt *points;

	void create_Pnts(int n){
		if (points){delete points;}
		points = new Pnt[n];
	}
};

#endif /*KLASSEN_H_*/
</code></pre>
<pre><code>#ifndef EINLESEN_H_
#define EINLESEN_H_

int toktoi(char *);
int read_parameter(int*, int*, int*, int*, char*);
int read_structures(Elem**, int, char*);

#endif /*EINLESEN_H_*/
</code></pre>
<pre><code>///// Einlesen.c
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

#include &quot;Klassen.h&quot;

#ifndef BUFLEN
#define BUFLEN 8000
#endif

... //hier habe ich nur 2 Funktionen stehen die für das Problem irrelevant sind

int read_Structures(Elem **Strukturen, int maxPoints, char *infile){

	ifstream xmlfile;
	char buf[BUFLEN];
	char *token;
	char separator[] = &quot; &lt;&gt;&quot;; //benutzte Trennzeichen
	enum status { 	structure,
					trace,
					point}status;
	int structureID;
	char name[30];
	int numPoints;
	Elem t;
	Pnt p;
	int pos;

	status = structure;

	xmlfile.open(infile, ios::in);
	while(!xmlfile.eof()){
		//liest zeilenweise von xmlfile
		xmlfile.getline(buf,BUFLEN);

		//splittet den Buffer in einzelne Tokens
		token = strtok(buf, separator);

		while(token!=NULL){

			Elem t(maxPoints);

			switch (status){				
			case structure:				
				if(!strncmp(token, &quot;structureID&quot;, 11)){
					structureID = toktoi(token);
					t.set_id(structureID);
				}
				else if(!strncmp(token, &quot;name&quot;, 4)){
					for(unsigned int i=6;i&lt;(strlen(token)-1);++i){
						name[i-6]=token[i];
						name[i-5]='\0';
					}
					t.set_name(name);
				}
				else if(!strcmp(token, &quot;Trace&quot;)){
					status = trace;
				}
				break;

			case trace:
				if(!strncmp(token, &quot;numPoints&quot;, 9)){
					numPoints = toktoi(token);
					t.set_numPoints(numPoints);
				}
				else if(!strcmp(token, &quot;Point&quot;))
					status = point;
				else if(!strcmp(token, &quot;/Trace&quot;))
					status = structure;
				break;

			case point:
				pos = toktoi(token);
				token = strtok(NULL, separator);
				p.set_x(toktoi(token));
				token = strtok(NULL, separator);
				p.set_y(toktoi(token));
				token = strtok(NULL, separator);
				t.add_pnt(p,pos);
				if(!strcmp(token, &quot;/Point&quot;)){
					status = trace;
				}
				break;

			default:
				break;

			(*Strukturen)[structureID] = t;
			}
			token = strtok(NULL, separator);
		}
	}
	xmlfile.close();

	return EXIT_SUCCESS;
}/* read_structures */
</code></pre>
<pre><code>///// Main
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

#include &quot;Klassen.h&quot;
#include &quot;Einlesen.h&quot;
//#include &quot;Routine.h&quot;

int main(int argc, char *argv[]) {

	int error;

	int numStructures = 1;
	int maxPoints = 1;
	int width = 1;
	int height = 1;
	error = read_parameter(&amp;numStructures, &amp;maxPoints, &amp;width, &amp;height, argv[1]);

	Elem Structures[numStructures];
	error = read_structures(&amp;Structures, maxPoints, argv[1]);

	return EXIT_SUCCESS;
}
</code></pre>
<p>Ich weiss, dass das nicht ganz sauber ist, aber die eingabedatei ist fest strukturiert und es fluppte auch. Der Fehler trat erst nach dem modularisieren auf, sprich als ich die einzelnen Datei-Module erzeugt habe. Daher müßte das ein Parameterfehler im Funktionsaufruf sein.</p>
<p>Hier nochmal der Compilerfehler:<br />
cannot convert `Elem (<em>)[((numStructures - 1) + 1)]' to `Elem**' for argument `1' to `int read_structures(Elem**, int, char</em>)'</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429815</guid><dc:creator><![CDATA[Flaut]]></dc:creator><pubDate>Thu, 03 Jan 2008 11:21:35 GMT</pubDate></item><item><title><![CDATA[Reply to komme nicht weiter&#x2F;Klassenfehler? on Thu, 03 Jan 2008 11:44:52 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#if !defined(POINT_HPP__INCLUDED)
#define POINT_HPP__INCLUDED

#if (_MSC_VER &gt;= 1300)
#pragma once
#endif // (_MSC_VER &gt;= 1300)

#include &lt;utility&gt; // std::pair

class Point
{
public:
    typedef std::pair&lt;long, long&gt; point_t;

private:
    point_t m_point;

public:
    Point(long x = 0, long y = 0) 
        : m_x(x), m_y(y)
    {}

public:
    long const&amp; get_x() const { return m_point.first; }
    long const&amp; get_y() const { return m_point.second; }
    point_t const&amp; get() const { return m_point; }
    void set_x(const long x) { m_point.first = x; }
    void set_y(const long y) { m_point.second = y; }
    void set(point_t const&amp; pt) { m_point = pt; }
};

#endif // POINT_HPP__INCLUDED
</code></pre>
<pre><code class="language-cpp">#if !defined(ELEMENT_HPP__INCLUDED)
#define ELEMENT_HPP__INCLUDED

#if (_MSC_VER &gt;= 1300)
#pragma once
#endif // (_MSC_VER &gt;= 1300)

#include &lt;string&gt;
#include &lt;vector&gt;

class Element
{
public:
    Element()
        : m_id(0)
    {}

public:
    void set_name(const char* name) { m_name = name;}
    const char* get_name() const { return m_name.c_str(); }

    void set_id(unsigned int id) { m_id = id; }
    unsigned int  get_id() const { return id; }

    const std::size_t get_point_count() const { return m_data.size(); }

    void add_point(Point const&amp; point) { m_data.push_back(point); }
    Point const&amp;  get_point(const std::size_t pos) { return m_data.at(pos); }

private:
    unsigned int m_id;
    std::string m_name;
    std::vector&lt;Point&gt; m_data;
};

#endif // ELEMENT_HPP__INCLUDED
</code></pre>
<p>So. Deine Klasse war katastrophal falsch! Du reservierst andauernt speicher, gibst diesen nicht frei und greifst auf Bereiche zu ohne zu Prüfen ob diese im Range sind. Dann hälst du dich natürlich nicht an die const correctness und lässt jeden deine !private-Daten bearbeiten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1429838</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1429838</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Thu, 03 Jan 2008 11:44:52 GMT</pubDate></item></channel></rss>