copy Linked List Recursivly (exit 1 return status error)
In part of my program I am supposed to write a copy method that copies a linked list recursively. I may or may not have figured out how to do that. My current try gives me the following error:
collect2: ld returned 1 exit status
Yes my program has a main.
Here are the snippet of code that is giving me the trouble followed by the two header files needed.
Any advice would be greatly appreciated.
Kit
#include <iostream>
#include "Term.h"
#include "Poly.h"
using namespace std;
//OTHER METHODS OMITED
void Poly::copy (const Term * sourcePtr, Term * & destinationPtr)
{
//if sourcePtr is NULL
if (sourcePtr == 0)
{
destinationPtr = 0; //set destinationPtr to NULL
}
else
{
//IF THIS LINE BELOW IS COMMENTED OUT EXIT STATUS ERROR GOES AWAY
destinationPtr = new Term(sourcePtr->coeff, sourcePtr->expo);
copy(sourcePtr->linkPtr, destinationPtr->linkPtr); // recur for the rest
//ANOTHER TRY WITH SAME ERROR
//Term* newTerm = new Term(sourcePtr->coeff, sourcePtr->expo);
//destinationPtr = newTerm->linkPtr;
//copy(sourcePtr->linkPtr, destinationPtr->linkPtr); // recur for the rest
}
}//end copy method
//LOGIC GIVEN IN ASSIGNMENT
//if sourcePtr is NULL //set destinationPtr to NUL
//create a new Term that has the coefficient and exponent values of the
//Term pointed to by sourcePtr
//assign the new Term to destination Ptr
//Copy (next Term for sourcePtr, next Term for destinationPtr)
//endif
#include <iostream>
#include "Term.h"
#ifndef POLY_H
#define POLY_H
using namespace std;
class Poly
{
friend ostream & operator<< (ostream &, const Poly &); //output operator
friend istream & operator>> (istream &, Poly &); //input operator
public:
//constructors
Poly (); //default constructor
Poly (const Poly&); //copy constructor
~Poly (); //deconstructor
//relational operator method prototypes
bool operator== (const Poly&) const; //equality operator
//assignment operator
Poly& operator= (const Poly&); //assignment Poly = Poly
//arithmatic operators
Poly& operator+= (const Term&); //Poly += Term
Poly operator+ (const Poly&) const; //Poly + Poly
Poly operator- (const Poly&); //Poly - Poly
Poly operator* (const Poly&); //Poly * Poly
private:
//private data members
Term* headPtr; //address of the first Term in the linked list
//private method prototypes
void copy (const Term *, Term * &); //creates a copy of an existing Poly object
void dismantle(Term * &); //deletes all of the Terms in an existing Poly object
};
#endif
#include <iostream>
#ifndef TERM_H
#define TERM_H
using namespace std;
class Poly; //a class called Poly exists
class Term
{
//friend classes to be given access to this class
friend class Poly;
friend ostream & operator<< (ostream &, const Term&); //Term's output operator
friend istream & operator>> (istream &, Term&); //Term's input operator
friend ostream & operator<< (ostream &, const Poly&); //Polly's output operator
public:
//constructors
Term (int = 0, int = 0, Term* = 0); //constructor
//operator method prototypes
Term operator* (const Term&) const;
private:
//private data members
int coeff;
int expo;
Term* linkPtr;
};
#endif

