PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Fehler bei Codetrennung



KravenZ
06.12.06, 21:37
Hi,

Hab eine wichtige Frage bei der ich nicht weiterkomme. Ich habe mit C++ eine Klasse geschrieben und sie schön und Header und Definitionsdatei aufgeteilt. Nun binde ich die Header in die Code datei ein die das mainProgramm enthält. Sobald ich nun compilieren will erhalte ich eine Fehlermeldung und zwar:


OGLWidget.o: In function `SWP0607::OGLWidget::drawBall(SWP0607::MyVector3Df )':
/home/bulczak/Desktop/Softwarepraktikum/OGLWidget.cc:276: undefined reference to `SWP0607::MyVector3Df::z()'
/home/bulczak/Desktop/Softwarepraktikum/OGLWidget.cc:276: undefined reference to `SWP0607::MyVector3Df::y()'
/home/bulczak/Desktop/Softwarepraktikum/OGLWidget.cc:276: undefined reference to `SWP0607::MyVector3Df::x()'
collect2: ld returned 1 exit status
make: *** [Softwarepraktikum] Fehler 1


Hier ist meine Headerdatei:


#ifndef _MY_VECTOR3DF_HH_
#define _MY_VECTOR3DF_HH_

namespace SWP0607 {

class MyVector3Df
{
private:
float m_x, m_y, m_z; // Vektorkomponenten
public:
// Konsturktor(en)
MyVector3Df();
MyVector3Df(const MyVector3Df & v);
MyVector3Df(const float, const float, const float);

// Zugriffsmethoden

inline float x();
inline float y();
inline float z();
inline void setX(float);
inline void setY(float);
inline void setZ(float);


// Operatoren

// arithmetische Operatoren
inline MyVector3Df operator + (const MyVector3Df & v); // Komponentenweise
inline MyVector3Df operator - (const MyVector3Df & v); // Komponentenweise
inline MyVector3Df operator * (const MyVector3Df & v); // Komponentenweise
inline MyVector3Df operator / (const MyVector3Df & v); // Komponentenweise
inline MyVector3Df operator * (const float f); // Skalarmultiplikation
friend MyVector3Df operator * (const float f, const MyVector3Df & v);
inline MyVector3Df operator / (const float f); // Skalardivision

// Zuweisungsoperatoren
MyVector3Df& operator = (const MyVector3Df & v);
MyVector3Df& operator += (const MyVector3Df & v);
MyVector3Df& operator -= (const MyVector3Df & v);
MyVector3Df& operator *= (const MyVector3Df & v);
MyVector3Df& operator /= (const MyVector3Df & v);

// Vergleichsoperatoren
bool operator == (const MyVector3Df & v);
bool operator != (const MyVector3Df & v);


// Methoden
inline float length(); // liefert Vektorlänge
inline float lengthSq(); // liefert Vektorlänge²


};
inline MyVector3Df operator * (const float f, const MyVector3Df & v);
}

#endif


Und hier die cc Datei


#include "myvector3df.hh"
#include <math.h>

namespace SWP0607 {

MyVector3Df::MyVector3Df()
{
}

MyVector3Df::MyVector3Df(const MyVector3Df & v) : m_x(v.m_x), m_y(v.m_y), m_z(v.m_z)
{
}

MyVector3Df::MyVector3Df(const float x,
const float y,
const float z) : m_x(x), m_y(y), m_z(z)
{
}

float MyVector3Df::x()
{
return m_x;
}

float MyVector3Df::y()
{
return m_y;
}

float MyVector3Df::z()
{
return m_z;
}

void MyVector3Df::setX(float nX)
{
m_x = nX;
}

void MyVector3Df::setY(float nY)
{
m_y = nY;
}

void MyVector3Df::setZ(float nZ)
{
m_z = nZ;
}

MyVector3Df MyVector3Df::operator + (const MyVector3Df & v)
{
return MyVector3Df(m_x + v.m_x,
m_y + v.m_y,
m_z + v.m_z);
}

MyVector3Df MyVector3Df::operator - (const MyVector3Df & v)
{
return MyVector3Df(m_x - v.m_x,
m_y - v.m_y,
m_z - v.m_z);
}

MyVector3Df MyVector3Df::operator * (const MyVector3Df & v)
{
return MyVector3Df(m_x * v.m_x,
m_y * v.m_y,
m_z * v.m_z);
}

MyVector3Df MyVector3Df::operator / (const MyVector3Df & v)
{
return MyVector3Df(m_x / v.m_x,
m_y / v.m_y,
m_z / v.m_z);
}

MyVector3Df MyVector3Df::operator * (const float f)
{
return MyVector3Df(m_x * f,
m_y * f,
m_z * f);
}

MyVector3Df operator * (const float f, const MyVector3Df & v)
{
return MyVector3Df(v.m_x * f,
v.m_y * f,
v.m_z * f);
}

MyVector3Df MyVector3Df::operator / (const float f)
{
return MyVector3Df(m_x / f,
m_y / f,
m_z / f);
}

MyVector3Df& MyVector3Df::operator = (const MyVector3Df & v)
{
m_x = v.m_x;
m_y = v.m_y;
m_z = v.m_z;

return *this;
}

MyVector3Df& MyVector3Df::operator += (const MyVector3Df & v)
{
m_x += v.m_x;
m_y += v.m_y;
m_z += v.m_z;

return *this;
}

MyVector3Df& MyVector3Df::operator -= (const MyVector3Df & v)
{
m_x -= v.m_x;
m_y -= v.m_y;
m_z -= v.m_z;

return *this;
}

MyVector3Df& MyVector3Df::operator *= (const MyVector3Df & v)
{
m_x *= v.m_x;
m_y *= v.m_y;
m_z *= v.m_z;

return *this;
}

MyVector3Df& MyVector3Df::operator /= (const MyVector3Df & v)
{
m_x /= v.m_x;
m_y /= v.m_y;
m_z /= v.m_z;

return *this;
}

bool MyVector3Df::operator == (const MyVector3Df & v)
{
return (m_x == v.m_x) && (m_y == v.m_y) && (m_y == v.m_z);
}

bool MyVector3Df::operator != (const MyVector3Df & v)
{
return (m_x != v.m_x) || (m_y != v.m_y) || (m_y != v.m_z);
}

float MyVector3Df::length()
{
return sqrtf(m_x*m_x + m_y*m_y + m_z*m_z);
}

float MyVector3Df::lengthSq()
{
return m_x*m_x + m_y*m_y + m_z*m_z;
}

}


Die Fehlermeldung die ich da erhalte bezieht sich auf die Zugriffsmethoden weil ich nur die in der Hauptdatei benutzt habe. Aber sobald ich eine andere Methode benutze wird auch gemeckert.
Muss ich vielleicht etwas in der Makefile dazuschreiben?

schwarzbarde
06.12.06, 22:13
Ohne Dir auf die Füße treten zu wollen: Stelle die Frage doch bitte auf www.mrunix.de ;)

KravenZ
06.12.06, 22:57
Hab ich jetzt auch gemacht ^^ Aber hab die Lösung nun auch selber herrausgefunden ;)