getting undefined reference error

I've been trying to figure out this error on my own but can't seem to get it anywhere.

My header:

#ifndef POINT2D_H
#define POINT2D_H
class point2d {
point2d();
public:
// constructor:
point2d(double x, double y);
//read access functions
double x() const;
double y() const;
double modulus() const;
double argument() const;
// write access functions
point2d & x(double new_x);
point2d & y(double new_y);
point2d & modulus(double new_modulus);
point2d & argument(double new_argument);
private:
double x_;
double y_;
};
#endif


My cpp file:

#include "point2d.h"
#include <iostream>
using namespace std;

void showstate(point2d const & pt){
cout << pt.x() << '\n';
cout << pt.y() << '\n';
cout << "modulus: " << pt.modulus() << '\n';
cout << "argument: "<< pt.argument() << "\n\n";
}

int main(){
try{
point2d apt(3, 4);
showstate(apt);
apt.x(4);
apt.y(-3);
showstate(apt);
apt.modulus(10);
showstate(apt);
apt.argument(90);
showstate(apt);
}
catch(...){
cout << "\n***There was a problem***\n";
}
}


My implementation file:

#include "point2d.h"
#include "fgw_text.h"
#include <cmath>
using namespace std;

point2d::point2d():x_(0), y_(0) {}

double point2d::x() const {return x_;}
double point2d::y() const {return y_;}

point2d & point2d::x(double new_x){
x_ = new_x;
return *this;
}
point2d & point2d::y(double new_y){
y_ = new_y;
return *this;
}

double point2d::modulus() const {
return std::sqrt(x_*x_ + y_*y_);
}

point2d & point2d::modulus(double new_modulus) {
double const old_modulus(modulus());
double const scale(new_modulus/old_modulus);
x_ *= scale;
y_ *= scale;
return *this;
}

double point2d::argument() const {
return fgw::degrees(atan2(y_, x_));
}

point2d & point2d::argument(double new_argument){
double const mod(modulus());
x_ = mod * cos(fgw::radians(new_argument));
y_ = mod * sin(fgw::radians(new_argument));
return *this;
}


They all compile successfully but when I try to link the cpp and implementation file and execute it, it keeps giving me this error:

undefined reference to 'point2d::point2d(double, double)'


Anyone have a clue what the problem is? :(


I... don't see any definition of point2d::point2d(double x, double y). I see its declaration, but not definition. That string of text doesn't appear in your implementation file.

-Albatross
Last edited on
Haha thanks very much, completely missed. Got it working thanks to you! :P
Topic archived. No new replies allowed.