Hallo liebes Forum,
ich hab ein Problem mit xode. In der Uni lernen wir gerade ein bisschen c++ und wir sollen klassen erstellen.
Fast alle hier nutzen Linux (Fedora) mit Eclipse Juno und darauf funktioniert auch, was ich im folgenden schicke. Allerdings bekomme ich
jedes mal den o-linker error und ich finde in keinem Forum eine Lösung dafür. Ich habe versucht die build-architecture zu ändern usw - nix klappt.
Ich poste hier meine main.cpp und mein klassen und body file (getrennt durch ***), kopiert es euch rein und guckt mal was das ist. Ich komme damit nicht zurecht.
Ich würde mich über eure Hilfe freuen, Liebe Grüße
Willi
************************
main.cpp:
#include<iostream>
using namespace std;
#include "vektor.cpp"
int main()
{
Vektor3 A , B;
A.set(1,0,0);
B.set(1,2,3);
Vektor3 C(3,4,5); // Konstruktor wird gebraucht
C.set(7,8,9);
cout << "Der Vektor lautet: ";
A.pretty_print();
Vektor3 D = A+B; // C = A.operator+(B);
double skalar = A*B; // C = operator*(A,B);
D.pretty_print();
cout << skalar;
return 0;
}
**************************
vektor.cpp
#include "vektor.h"
void Vektor3::set(double x, double y, double z)
{
components[0] = x;
components[1] = y;
components[2] = z;
length = sqrt(x*x + y*y + z*z);
}
Vektor3::Vektor3(double x,double y,double z)
{
set(x,y,z);
}
Vektor3::Vektor3()
{
components[0] = 0;
components[1] = 0;
components[2] = 0;
length = 0;
}
void Vektor3:retty_print()
{
cout << "(" << components[0] << "," << components[1] << "," << components[2] << "), Length= " << length << "\n";
}
Vektor3 Vektor3:perator+(Vektor3 &E)
{
Vektor3 Erg;
Erg.set(components[0] + E.components[0], components[1] + E.components[1], components[2] + E.components[2]);
return Erg;
}
double operator*(Vektor3 &A, Vektor3 &B)
{
return A.components[0] * B.components[0] + A.components[1] * B.components[1] + A.components[2] * B.components[2];
}
*****************
vektor.h
#ifndef __Vektoren__vektor__
#define __Vektoren__vektor__
#include <math.h>
#include<iostream>
using namespace std;
class Vektor3{
private:
double components[3];
double length;
public:
void set(double x, double y, double z);
Vektor3 (double x, double y, double z);
Vektor3 ();
void pretty_print();
Vektor3 operator+(Vektor3 &E);
friend double operator*(Vektor3& A, Vektor3& B);
};
#endif /* defined(__Vektoren__vektor__) */
ich hab ein Problem mit xode. In der Uni lernen wir gerade ein bisschen c++ und wir sollen klassen erstellen.
Fast alle hier nutzen Linux (Fedora) mit Eclipse Juno und darauf funktioniert auch, was ich im folgenden schicke. Allerdings bekomme ich
jedes mal den o-linker error und ich finde in keinem Forum eine Lösung dafür. Ich habe versucht die build-architecture zu ändern usw - nix klappt.
Ich poste hier meine main.cpp und mein klassen und body file (getrennt durch ***), kopiert es euch rein und guckt mal was das ist. Ich komme damit nicht zurecht.
Ich würde mich über eure Hilfe freuen, Liebe Grüße
Willi
************************
main.cpp:
#include<iostream>
using namespace std;
#include "vektor.cpp"
int main()
{
Vektor3 A , B;
A.set(1,0,0);
B.set(1,2,3);
Vektor3 C(3,4,5); // Konstruktor wird gebraucht
C.set(7,8,9);
cout << "Der Vektor lautet: ";
A.pretty_print();
Vektor3 D = A+B; // C = A.operator+(B);
double skalar = A*B; // C = operator*(A,B);
D.pretty_print();
cout << skalar;
return 0;
}
**************************
vektor.cpp
#include "vektor.h"
void Vektor3::set(double x, double y, double z)
{
components[0] = x;
components[1] = y;
components[2] = z;
length = sqrt(x*x + y*y + z*z);
}
Vektor3::Vektor3(double x,double y,double z)
{
set(x,y,z);
}
Vektor3::Vektor3()
{
components[0] = 0;
components[1] = 0;
components[2] = 0;
length = 0;
}
void Vektor3:retty_print()
{
cout << "(" << components[0] << "," << components[1] << "," << components[2] << "), Length= " << length << "\n";
}
Vektor3 Vektor3:perator+(Vektor3 &E)
{
Vektor3 Erg;
Erg.set(components[0] + E.components[0], components[1] + E.components[1], components[2] + E.components[2]);
return Erg;
}
double operator*(Vektor3 &A, Vektor3 &B)
{
return A.components[0] * B.components[0] + A.components[1] * B.components[1] + A.components[2] * B.components[2];
}
*****************
vektor.h
#ifndef __Vektoren__vektor__
#define __Vektoren__vektor__
#include <math.h>
#include<iostream>
using namespace std;
class Vektor3{
private:
double components[3];
double length;
public:
void set(double x, double y, double z);
Vektor3 (double x, double y, double z);
Vektor3 ();
void pretty_print();
Vektor3 operator+(Vektor3 &E);
friend double operator*(Vektor3& A, Vektor3& B);
};
#endif /* defined(__Vektoren__vektor__) */