<?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[Linker Error bei Implementierung einer Headerdatei]]></title><description><![CDATA[<p>EDIT: Sorry, irgendwie funzen bei mir die Tags nicht, ich habe sowohl &quot;Code&quot; und &quot;cpp&quot; als auch &quot;quote&quot; probiert, aber die gehen beide nicht. <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="😞"
    /></p>
<p>EDIT II: Seltsam im zweiten Beitrag gehen die Tags. Also der saubere Code steht dort, sorry für das Durcheinander, wäre schön, wenn ein Mod da mal draufschauen könnte, warum das beim ersten Beitrag mit den Tags nicht geht, danke schon einmal.</p>
<p>Ich versuche mir gerade in Programm zu schreiben und arbeite dabei auch mit einer Klasse. Es geht darum Rechnungen mit mehreren himmelskörpern durchzuführen und diese will ich als Klasse vorher definieren. Die Klasse verfügt über verschiedene Attribute (Masse, Perizentrumsgeschwindigkeit, Perizentrumsposition) und diese können wiederum über einfache Textdateien abgespeichert, bzw. eingegeben werden.</p>
<p>Es gibt nun folgenden code</p>
<p>Die Headerdatei der Klasse grav_object</p>
<pre><code class="language-cpp">// Header für grav_object
#ifndef _GRAV_OBJECT_H_
#define _GRAV_OBJECT_H_

class grav_object

{

      public:

             grav_object(); 				//Constructors
             ~grav_object(); 				//Destructor

             double objectmass; 			//mass of the body
             double Rp;         			// pericentre radius (assuming that the pericentre is on the x-axis)
             double Vp;         			// pericentre velocity (see above)

             double get_objectmass(int massnumber); 	//accessing the body's mass
             double get_Rp(int massnumber); 		//accessing the body's pericentre radius
             double get_Vp(int massnumber); 		//accessing the body's pericentre velocity

};
#endif
</code></pre>
<p>Die CPP Datei der Klasse (die Funktionen sind identisch und fragen nur verschiedene Werte ab, sie funktionieren wie gewünscht, das habe ich in einer seperaten datei getestet):</p>
<pre><code class="language-cpp">// Implementierung grav_object

#include &quot;grav_object.h&quot;
#include &quot;stdlib.h&quot; 
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;

using namespace std;

      grav_object::grav_object()                            //Konstruktor
      {
                                 Rp = 0;
                                 Vp = 0;
                                 objectmass =0;
      }

      grav_object::~grav_object()                           // Destruktor
      {
      }

      double grav_object::get_objectmass(int massnumber)
      {
             bool error = false;
             string mass = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; mass;
                      if (mass==&quot;mass&quot; || mass == &quot;Mass&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; mass;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No mass has been found, please make sure your input is given as 'mass x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(mass);
             inStream &gt;&gt; objectmass;

             return objectmass;

             }

      double grav_object::get_Rp(int massnumber)
      {
             bool error = false;
             string radius = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; radius;
                      if (radius==&quot;Rp&quot; || radius == &quot;rp&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; radius;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No radius has been found, please make sure your input is given as 'radius x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(radius);
             inStream &gt;&gt; Rp;

             return Rp;

             }

      double grav_object::get_Vp(int massnumber)
             {
             bool error = false;
             string velocity = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; velocity;
                      if (velocity==&quot;Vp&quot; || velocity == &quot;vp&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; velocity;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No velocity has been found, please make sure your input is given as 'velocity x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(velocity);
             inStream &gt;&gt; Vp;

             return Rp;

}
</code></pre>
<p>Und jetzt die Quelldatei des Hauptprogramms:</p>
<pre><code class="language-cpp">#include &quot;grav_object.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;
#include &lt;stdlib.h&gt; 

using namespace std;

int main()
{
    grav_object planet;    
    double masse = 0;  

    masse = planet.get_objectmass(1);        
    cout &lt;&lt; masse &lt;&lt; endl;

    cout &lt;&lt; &quot;Zum Beenden&quot;&lt;&lt; endl;
    system(&quot;PAUSE&quot;);

 return 0;   
}
</code></pre>
<p>Ich bekomme folgenden Fehler:</p>
<p>[Linker error] undefined reference to <code>grav\_object::grav\_object()' \[Linker error\] undefined reference to</code>grav_object::get_objectmass(int)'<br />
[Linker error] undefined reference to <code>grav\_object::~grav\_object()' \[Linker error\] undefined reference to</code>grav_object::~grav_object()'<br />
ld returned 1 exit status</p>
<p>Interessant dabei ist imho, dass ich den Fehler des Destruktors zwei mal bekomme. Ich dachte auch erst, dass der Grund ist, dass die Headerdatei nicht gefunden wird, dies ist aber nicht das Problem, denn ich habe einfach mal den Namen verändert und bekam dann den Fehler, dass die Datei unbekannt ist.<br />
Ich habe auch ausprobiert einfach einen falschen Funktionsnamen zu verwenden, bei richtiger Headerdatei, auch da bekam ich den Fehler, dass die Funktion nicht existiert... Sprich, die Headerdatei wird gefunden und auch richtig gelesen.<br />
Wenn ich statt der Headerdatei die cpp-Datei include funktioniert das ganze, wäre ja aber nicht im Sinne des Erfinders. Ich hoffe es kann mir jemand helfen.</p>
<p>Ich benutze Dev-C++ Bloodshed und habe Windows Vista 32 bit SP2.<br />
Danke schon einmal für die mögliche Unterstützung.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/259230/linker-error-bei-implementierung-einer-headerdatei</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 22:19:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/259230.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Jan 2010 17:43:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Linker Error bei Implementierung einer Headerdatei on Wed, 20 Jan 2010 19:42:08 GMT]]></title><description><![CDATA[<p>EDIT: Sorry, irgendwie funzen bei mir die Tags nicht, ich habe sowohl &quot;Code&quot; und &quot;cpp&quot; als auch &quot;quote&quot; probiert, aber die gehen beide nicht. <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="😞"
    /></p>
<p>EDIT II: Seltsam im zweiten Beitrag gehen die Tags. Also der saubere Code steht dort, sorry für das Durcheinander, wäre schön, wenn ein Mod da mal draufschauen könnte, warum das beim ersten Beitrag mit den Tags nicht geht, danke schon einmal.</p>
<p>Ich versuche mir gerade in Programm zu schreiben und arbeite dabei auch mit einer Klasse. Es geht darum Rechnungen mit mehreren himmelskörpern durchzuführen und diese will ich als Klasse vorher definieren. Die Klasse verfügt über verschiedene Attribute (Masse, Perizentrumsgeschwindigkeit, Perizentrumsposition) und diese können wiederum über einfache Textdateien abgespeichert, bzw. eingegeben werden.</p>
<p>Es gibt nun folgenden code</p>
<p>Die Headerdatei der Klasse grav_object</p>
<pre><code class="language-cpp">// Header für grav_object
#ifndef _GRAV_OBJECT_H_
#define _GRAV_OBJECT_H_

class grav_object

{

      public:

             grav_object(); 				//Constructors
             ~grav_object(); 				//Destructor

             double objectmass; 			//mass of the body
             double Rp;         			// pericentre radius (assuming that the pericentre is on the x-axis)
             double Vp;         			// pericentre velocity (see above)

             double get_objectmass(int massnumber); 	//accessing the body's mass
             double get_Rp(int massnumber); 		//accessing the body's pericentre radius
             double get_Vp(int massnumber); 		//accessing the body's pericentre velocity

};
#endif
</code></pre>
<p>Die CPP Datei der Klasse (die Funktionen sind identisch und fragen nur verschiedene Werte ab, sie funktionieren wie gewünscht, das habe ich in einer seperaten datei getestet):</p>
<pre><code class="language-cpp">// Implementierung grav_object

#include &quot;grav_object.h&quot;
#include &quot;stdlib.h&quot; 
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;

using namespace std;

      grav_object::grav_object()                            //Konstruktor
      {
                                 Rp = 0;
                                 Vp = 0;
                                 objectmass =0;
      }

      grav_object::~grav_object()                           // Destruktor
      {
      }

      double grav_object::get_objectmass(int massnumber)
      {
             bool error = false;
             string mass = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; mass;
                      if (mass==&quot;mass&quot; || mass == &quot;Mass&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; mass;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No mass has been found, please make sure your input is given as 'mass x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(mass);
             inStream &gt;&gt; objectmass;

             return objectmass;

             }

      double grav_object::get_Rp(int massnumber)
      {
             bool error = false;
             string radius = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; radius;
                      if (radius==&quot;Rp&quot; || radius == &quot;rp&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; radius;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No radius has been found, please make sure your input is given as 'radius x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(radius);
             inStream &gt;&gt; Rp;

             return Rp;

             }

      double grav_object::get_Vp(int massnumber)
             {
             bool error = false;
             string velocity = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; velocity;
                      if (velocity==&quot;Vp&quot; || velocity == &quot;vp&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; velocity;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No velocity has been found, please make sure your input is given as 'velocity x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(velocity);
             inStream &gt;&gt; Vp;

             return Rp;

}
</code></pre>
<p>Und jetzt die Quelldatei des Hauptprogramms:</p>
<pre><code class="language-cpp">#include &quot;grav_object.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;
#include &lt;stdlib.h&gt; 

using namespace std;

int main()
{
    grav_object planet;    
    double masse = 0;  

    masse = planet.get_objectmass(1);        
    cout &lt;&lt; masse &lt;&lt; endl;

    cout &lt;&lt; &quot;Zum Beenden&quot;&lt;&lt; endl;
    system(&quot;PAUSE&quot;);

 return 0;   
}
</code></pre>
<p>Ich bekomme folgenden Fehler:</p>
<p>[Linker error] undefined reference to <code>grav\_object::grav\_object()' \[Linker error\] undefined reference to</code>grav_object::get_objectmass(int)'<br />
[Linker error] undefined reference to <code>grav\_object::~grav\_object()' \[Linker error\] undefined reference to</code>grav_object::~grav_object()'<br />
ld returned 1 exit status</p>
<p>Interessant dabei ist imho, dass ich den Fehler des Destruktors zwei mal bekomme. Ich dachte auch erst, dass der Grund ist, dass die Headerdatei nicht gefunden wird, dies ist aber nicht das Problem, denn ich habe einfach mal den Namen verändert und bekam dann den Fehler, dass die Datei unbekannt ist.<br />
Ich habe auch ausprobiert einfach einen falschen Funktionsnamen zu verwenden, bei richtiger Headerdatei, auch da bekam ich den Fehler, dass die Funktion nicht existiert... Sprich, die Headerdatei wird gefunden und auch richtig gelesen.<br />
Wenn ich statt der Headerdatei die cpp-Datei include funktioniert das ganze, wäre ja aber nicht im Sinne des Erfinders. Ich hoffe es kann mir jemand helfen.</p>
<p>Ich benutze Dev-C++ Bloodshed und habe Windows Vista 32 bit SP2.<br />
Danke schon einmal für die mögliche Unterstützung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1842146</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1842146</guid><dc:creator><![CDATA[ZeroGRanger]]></dc:creator><pubDate>Wed, 20 Jan 2010 19:42:08 GMT</pubDate></item><item><title><![CDATA[Reply to Linker Error bei Implementierung einer Headerdatei on Wed, 20 Jan 2010 19:40:50 GMT]]></title><description><![CDATA[<p>Header Datei:</p>
<pre><code class="language-cpp">// Header für grav_object
#ifndef _GRAV_OBJECT_H_
#define _GRAV_OBJECT_H_

class grav_object

{

      public:

             grav_object(); 				//Constructors
             ~grav_object(); 				//Destructor

             double objectmass; 			//mass of the body
             double Rp;         			// pericentre radius (assuming that the pericentre is on the x-axis)
             double Vp;         			// pericentre velocity (see above)

             double get_objectmass(int massnumber); 	//accessing the body's mass
             double get_Rp(int massnumber); 		//accessing the body's pericentre radius
             double get_Vp(int massnumber); 		//accessing the body's pericentre velocity

};
#endif
</code></pre>
<p>Quelldatei für grav_object</p>
<pre><code class="language-cpp">// Implementierung grav_object

#include &quot;grav_object.h&quot;
#include &quot;stdlib.h&quot; 
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;

using namespace std;

      grav_object::grav_object()                            //Konstruktor
      {
                                 Rp = 0;
                                 Vp = 0;
                                 objectmass =0;
      }

      grav_object::~grav_object()                           // Destruktor
      {
      }

      double grav_object::get_objectmass(int massnumber)
      {
             bool error = false;
             string mass = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; mass;
                      if (mass==&quot;mass&quot; || mass == &quot;Mass&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; mass;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No mass has been found, please make sure your input is given as 'mass x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(mass);
             inStream &gt;&gt; objectmass;

             return objectmass;

             }

      double grav_object::get_Rp(int massnumber)
      {
             bool error = false;
             string radius = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; radius;
                      if (radius==&quot;Rp&quot; || radius == &quot;rp&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; radius;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No radius has been found, please make sure your input is given as 'radius x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(radius);
             inStream &gt;&gt; Rp;

             return Rp;

             }

      double grav_object::get_Vp(int massnumber)
             {
             bool error = false;
             string velocity = &quot;0&quot;;                         
             //with massnumber the filename is created     
             string filename(&quot;0&quot;);
             int name_length = 0;

             ostringstream outStream;
             outStream &lt;&lt; massnumber;
             filename = outStream.str();

             filename.insert(0, &quot;mass&quot;);              //the name is added the addition &quot;mass&quot;
             name_length = filename.length();         // reads the length of the string
             filename.insert(name_length, &quot;.dat&quot;);  // the filename is completed to massx.dat where x is the content of massnumber

             //aus der Datei die Position der Masse finden, Masse auslesen (if-Abfrage)

             ifstream file_in;
             file_in.open(filename.c_str(), ios::in);       // .c_str() nicht vergessen, sonst funktioniert die Abfrage nicht!

             do
             {
                file_in &gt;&gt; velocity;
                      if (velocity==&quot;Vp&quot; || velocity == &quot;vp&quot;)                  // the file is searched for an entry of the mass
                      {
                         file_in &gt;&gt; velocity;                              // if so the value behind mass is input into the string mass
                         error = false;
                      }
                      else 
                      {
                           error = true;                               // if no value is found, error is set to true
                      };

             }while(!file_in.eof());

             if (error == true)       
             {cout &lt;&lt; &quot;No velocity has been found, please make sure your input is given as 'velocity x' where x is the correct value&quot; &lt;&lt; endl;
                  };                                                   // error message that no mass has been given

             istringstream inStream(velocity);
             inStream &gt;&gt; Vp;

             return Rp;

}
</code></pre>
<pre><code class="language-cpp">#include &quot;grav_object.h&quot;
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;
#include &lt;stdlib.h&gt; 

using namespace std;

int main()
{
    grav_object planet;    
    double masse = 0;  

    masse = planet.get_objectmass(1);        
    cout &lt;&lt; masse &lt;&lt; endl;

    cout &lt;&lt; &quot;Zum Beenden&quot;&lt;&lt; endl;
    system(&quot;PAUSE&quot;);

 return 0;   
}
</code></pre>
<p>Die Fehlermeldung:</p>
<pre><code class="language-cpp">[Linker error] undefined reference to `grav_object::grav_object()' 
  [Linker error] undefined reference to `grav_object::get_objectmass(int)' 
  [Linker error] undefined reference to `grav_object::~grav_object()' 
  [Linker error] undefined reference to `grav_object::~grav_object()' 
  ld returned 1 exit status
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1842201</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1842201</guid><dc:creator><![CDATA[ZeroGRanger]]></dc:creator><pubDate>Wed, 20 Jan 2010 19:40:50 GMT</pubDate></item><item><title><![CDATA[Reply to Linker Error bei Implementierung einer Headerdatei on Wed, 20 Jan 2010 20:16:48 GMT]]></title><description><![CDATA[<p>Du gibst offensichtlich den aus der Quelldatei für grav_object erzeugten Objektcode nicht beim Linken des aus der main erzeugten Codes an. Wie das geht, findest du in der Doku deines Linkers/Compilers. Oder wenn jemand der sich mit dev C++ auskennt dies liest, kann er es dir auch sagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1842236</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1842236</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Wed, 20 Jan 2010 20:16:48 GMT</pubDate></item><item><title><![CDATA[Reply to Linker Error bei Implementierung einer Headerdatei on Wed, 20 Jan 2010 21:09:23 GMT]]></title><description><![CDATA[<p>Zudem solltest du von DevC++ lieber zu einer aktuellen C++ IDE wechseln (z.B. Code::Blocks oder Visual C++ Express 2008)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1842279</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1842279</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Wed, 20 Jan 2010 21:09:23 GMT</pubDate></item></channel></rss>