Anfängerfrage: Linker error



  • Hallo allerseits

    Muss eine eigentlich einfache Übung in objektorientierter Programmierung lösen. Das Programm ist aufgeteilt in ein Header-, Main- und Implementierungsfile. Beim Compilieren erhalte ich nun immer die Fehlermeldung "[Linker error] undefined reference to `Point::Point(double, double)'". Ich verwende Dev C++ Vers. 4.9. Kann mir bei diesem Problem vielleicht jemand weiterhelfen?

    main.cpp

    #include "header.h"
    
    int main()
    {
        double dx(0), dy(0), axValue(2);
        Point p1(0,0);
        cout<<"x und y Werte eingeben: \n";
        cin>>dx;
        cin>>dy;
        p1.setPoint(dx,dy);
        cout<<"Die Achse um "<<axValue<<" verschieben"<<endl;
        p1.shiftAxis(axValue);
        cout<<"\nPosition von P1: x= "<<p1.getX()<<" y= "<<p1.getY()<<endl;
        Point p2(p1);
        cout<<"\nPosition von p2: "<<endl;
        p2.showPoint();
        system("PAUSE");
        return 0;
    }
    

    koordinaten.cpp:

    #include "header.h"
    
    void Point::setPoint(double x,double y){
         _x=x;
         _y=y;
    }
    void Point::showPoint (){
         cout<<_x<<" "<<_y<<endl;
    }
    double Point::getX(){
           return _x;
    }
    double Point::getY(){
           return _y;
    }
    void Point::shiftAxis (double value){
         _x=_x+value;
         _y=_y+value;
    }
    

    header.h:

    #include <iostream>
    #include <math.h>
    
    using namespace std;
    
    class Point{
          public:
                 Point (double x,double y);
                 Point (const Point &P);
                 void setPoint(double x,double y);
                 void showPoint();
                 double getX();
                 double getY();
                 void shiftAxis (double value);
          private:
                  double _x;
                  double _y;
    };
    

    Danke für eure Hilfe!! 🙂

    Gruss
    David



  • Du hast den Konstruktor nicht implementiert



  • JustAnotherNoob schrieb:

    Du hast den Konstruktor nicht implementiert

    genau so sieht das aus... deklariert hast du ihn, aber die definition steht noch aus. die methoden hingegen hast du brav definiert 😉
    und benutze doch bitte das nächste mal den "C/C++" tag anstelle des "Code"-Tags. ist etwas verwirrend, sieht aber schoener aus


Anmelden zum Antworten