1

When I try to overload the copy constructor, it gives me the following error code.
I encountered similar error message when I was trying to overload the << operator.

I fixed it by defining inside header

However, this time the same trick does not work..

How do I fix this and What is really going on to cause this error message?

Here is my copy constructor definition

template <class ItemType>
void List342<ItemType>::operator=(List342 &source)
{
Node *sNode, *dNode, *insNode;

if (this == &source) return;

this->Clear();
if (source.head == NULL)
{
    return;
}
dNode = new Node;
dNode->value = (source.head)->value;
this->head = dNode;
sNode = (source.head)->next;
while (sNode != NULL)
{
    insNode = new Node;
    insNode->value = sNode->value;
    dNode->next = insNode;
    dNode = dNode->next;
    sNode = sNode->next;
}
}

And here is my header file.

#ifndef LIST342_H_
#define LIST342_H_

#include <iostream>
#include <string>
using namespace std;

template <class ItemType>
class List342 {

friend ostream& operator<<(ostream &outStream, const List342 &list)
{
    Node *pNode;

    pNode = list.head;
    while (pNode != NULL)
    {
        outStream << *pNode->data;
        pNode = pNode->next;
    }
    return outStream;
}

public:
List342();
List342(List342<ItemType> &);
~List342();

bool BuildList(string FileName);
bool Insert(ItemType *obj);
bool Remove(ItemType target, ItemType &result);//check
bool Peek(ItemType target, ItemType &result);//check
bool isEmpty();
void ClearList();
bool Merge(List342 &list1, List342 &list2);

List342 operator+(const List342 &list) const;
List342 operator+=(const List342 &list);

bool operator==(const List342 &list) const;
bool operator!=(const List342 &list) const;

void operator=(List342 &);

private:
struct Node {
    ItemType *data;
    Node *next;
};
Node *head;
};
#endif /* LIST342_H_ */
dandan78
  • 13,328
  • 13
  • 64
  • 78
nugget
  • 11
  • 4
  • What is the error message? Is that definition inside a cpp file? – Marco A. Oct 29 '14 at 10:06
  • Undefined symbols for architecture x86_64: "List342::List342(List342&)", referenced from: _main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) – nugget Oct 29 '14 at 10:08
  • this is the error message i get – nugget Oct 29 '14 at 10:08
  • um... could u refer me to the source if this is a duplicate..? i couldnt find answers to this... – nugget Oct 29 '14 at 10:09

0 Answers0