1

I'm new to C++ and I'm learning template classes and also dynamic memory allocation so if there are silly errors here I apologize. I can't tell exactly what the issue is in this code, but I can't seem to get the compiler to give me anything other than..

Undefined                       first referenced
 symbol                             in file
indexList<timecard>::operator=(indexList<timecard> const&)/var/tmp//ccgqjCOv.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
template <class T>
indexList<T>& indexList<T>::operator=(const indexList<T> &other) const{
  if(this != &other){
    name = other.name;
    ssn = other.ssn;
    hours = other.hours;
    payRate = other.payRate;
    numOfDependents = other.numOfDependents;
    unionMem = other.unionMem;

    delete list;

    list = new T[maxSize];

    *list = *(other.list);
  }//end if

  return *this;
}
Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196
  • Whatever your problem, it's probably in http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix On a side note, you're most likely using the wrong form of `delete`, but you should be using the copy-swap idiom. – chris Mar 24 '14 at 01:15

1 Answers1

0

The final const qualifier, before {, does not belong there.

I'm not sure why you get this particular error, since the function is in fact defined, but all the assignments name = etc are illegal because this is const. But, the copy assignment operator is a special function, and the compiler really isn't expecting to see this signature.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • I wasn't sure if that was redundant or not but thank you - I'll remove it – user3453691 Mar 24 '14 at 01:23
  • @user3453691 No, that is significant and harmful. – Potatoswatter Mar 24 '14 at 01:24
  • The reason it causes an undefined-symbol error is because the linker is looking for a non-const version of the function, and no non-const version was defined, since the definition said `const` when it shouldn't have. – Wyzard Mar 24 '14 at 01:25
  • @Wyzard This lookup isn't the linker's job, though. The function must have been implicitly declared but not implicitly defined. – Potatoswatter Mar 24 '14 at 03:52