0

I know there are many linkage error questions similar to mine, but I haven't been able to fix it with any of the responses. I've made sure to add the correct scope resolution operators and give my constructors and destructors bodies, but the error is still there. Can anyone give me a hint besides "this has already been answered"?

Xx.obj : error LNK2019: unresolved external symbol "public: __thiscall Y::Y(void)" (??0Yy@@QAE@XZ) referenced in function _main

This is the relevant code:

  #include <iostream>

class Xx
{
    X::X() {};
    X::~X() {};
}; 
class Y : public X
{
public: //added public
    Y::Y();
    Y::~Y();       
};

int main()
{
    X *x = new Y;
    Y *y = new Y; //turned new Y to new X
    delete &x; //added deletes
    delete &y; //added deletes
    return 0;
}
user3750325
  • 1,502
  • 1
  • 18
  • 37
  • 2
    I don't think it's fair to downvote this question. It's very difficult when you're starting out to identify linker issues, and they're pretty unsearchable and relative only to the code written. Sometimes it's just easier to give someone like this a quick answer and move on than to slap them with a downvote for an otherwise "unhelpful" question on SO. – Will Custode May 06 '15 at 02:57

1 Answers1

2

You need to define the constructor to Yy.

You'll notice for Xx you've defined your constructor as follows:

Xx::Xx() {};

The curly braces are the body (or definition) of the method. Your declaration of the constructor for Yy looks as follows:

Yy::Yy();

You're missing your body (based on the code you've provided) and I assume you probably want to follow the same pattern from your Xx class. Simply change it to the following code:

Yy::Yy() {};

To wit, you're also missing the definition for your destructor (the method declared in Yy that starts with a ~) for Yy.

Will Custode
  • 4,576
  • 3
  • 26
  • 51