0

I have a custom class and am trying to create an operator overload function for =. Unfortunately the error I get does not point to a specific line or error I just get the following error.

unresolved external symbol "public: int __thiscall sequence::size(void)const " (?size@sequence@@QBEHXZ) referenced in function "public: void __thiscall sequence::operator=(class sequence const &)" (??4sequence@@QAEXABV0@@Z)

It is on file Sequence2.obj line 1. As that is not a file I edit, I am a little unsure what the error is in the function.

Sequence2.cpp

void sequence::operator=(const sequence & source)
{
    if (size() <= source.size()) {

        delete[] data;

        data = new value_type[source.size()];
        current_index = -1;
        used = 0;
    }
    else {

        delete[] data;

        data = new value_type[source.size() * 2];
        current_index = -1;
        used = 0;
    }

    for (int i = 0; i < source.size(); i++)
    {
        data[i] = source.data[i];
        used++;
        current_index++;
    }
}

The size function, just returns the size of the sequence. On the Main.cpp I just have the following.

sequence test; // A sequence that we’ll perform tests on
sequence test2;

test.insert(33);
test.insert(35);
test.insert(36);

test2 = test;
Buddy
  • 10,874
  • 5
  • 41
  • 58
Brandon Turpy
  • 883
  • 1
  • 10
  • 32
  • 9
    The error has little to do with `operator =` itself. The compiler (linker) tells you that you forgot to define `size()` function. Where's the definition for `size()`? – AnT stands with Russia Jan 13 '16 at 03:04

1 Answers1

0

The "unresolved external" error happens during the link step of compilation. See this question for more detail. Note that in compilation step the compiler made Sequence2.obj from Sequence2.cpp (and everthing it includes).

And yes, linker errors are a bit trickier than those compiler errors that happen during the actual compilation of source code.

I guess that somewhere in your code you have something like

class sequence
{
    // ... some declarations

    int size();

    // ... more declarations
}

but there is no corresponding

int sequence::size()
{
    // implementation of size()
}

Or maybe there is an implementation of size() but it is not compiled. Check your project settings / makefile in this case. Or it has been compiled but the result '.obj' file is not used by the linker.

The error message at least claims the linker does not know about an .obj file that contains the translated (i.e. compiled) counterpart of the implementation of size().

Community
  • 1
  • 1
TobiMcNamobi
  • 4,687
  • 3
  • 33
  • 52