Undefined Reference during linking

I'm a student working on an assignment, but am stuck in an area. The assignment is to do some basic arithmetic, and the three files I am working on compile fine individually, but when I try to link them I receive the following error: undefined reference to `Complex::Complex(double, double)'. I will only post the parts of the code I think pertain to the problem. I'd greatly appreciate some help!

Btw, the editor I am using is JGrasp, and the compiler is cygwin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// This is Complex.h

#ifndef COMPLEX_H
#define COMPLEX_H

class Complex
{
public:
	Complex( double, double ); // constructor
	Complex(); // default constructor
	Complex add( const Complex& ); 
	Complex subtract( const Complex& );
	void setComplexNumber( double, double );
private:
	double realPart;
	double imaginaryPart;
}; // end class Complex

#endif


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// This is Complex.cpp

#include <iostream> 
using namespace std;

#include "Complex.h"

Complex::Complex( double real, double imaginary )
{ 
   setComplexNumber( real, imaginary ); 
} // end Complex constructor

void Complex::setComplexNumber( double rp, double ip ) 
{
   realPart = rp;
   imaginaryPart = ip;
} // end function setComplexNumber  


1
2
3
4
5
6
7
8
9
10
11
// This is ComplexTest.cpp

#include <iostream> 
using namespace std;

#include "Complex.h"

int main()
{
   Complex a( 1, 7 ), b( 9, 2 ), c; // create three Complex objects 
} // end main 
Quick note: You need to have .0 at the end of all your floating point numbers. That includes doubles. :)

-Albatross
Last edited on
Quick note: You need to have .0 at the end of all your floating point numbers. That includes doubles. :)

-Albatross


Yes I forgot about that :) I went ahead and turned those integers into doubles but unfortunately I still get the undefined reference error :(
This builds just fine for me... how are you linking your files?

-Albatross
I'm not sure if this properly answers your question, but I'm linking the files seperately by using the "compile and link file" function in jGrasp.

Btw it just occured to me that there might be an issue with the linking process so I put all the code into just one file and now it works without any errors! Apparently the problem is related to jGrasp itself and not the code. Thank you very much for your time! :) Next time I'll just avoid linking seperate files.
Topic archived. No new replies allowed.