Why am i getting these Link errors?

Posts 16 of 6 · Page 1 of 1
Why am i getting these Link errors?
Code:
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall mammal::mammal(void)" (??0mammal@@QAE@XZ) referenced in function "public: __thiscall dog::dog(void)" (??0dog@@QAE@XZ)
1>main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall mammal::~mammal(void)" (??1mammal@@UAE@XZ) referenced in function "public: virtual __thiscall dog::~dog(void)" (??1dog@@UAE@XZ)
[php]#include <iostream>
using namespace std;
class mammal
{
public:
mammal(); //constructor
virtual ~mammal(); //destructor
virtual void speak() const { cout << "mammal\n"; }
};



class dog : public mammal
{
public:

void speak() const { cout << "dog\n"; }
};



class human : public mammal
{
public:

void speak() const { cout << "dog\n"; }
};


class bomberman : public mammal
{
public:

void speak() const { cout << "Bomberman pwns \n"; }
};[/php]


[php]#include "classes.h"

int main()
{
mammal *ptr;
mammal *speak;
startLoop:
while(true)
{
char choice;
cout << "(d)og (h)uman (b)omberman\n";
cin >> choice;
switch(choice)
{
case 'd':
ptr = new dog;
break;
case 'h':
ptr = new human;
break;
case 'b':
ptr = new bomberman;
break;
case 'q':
goto exit;
default:
cout << "not a choice, choose again\n";
goto startLoop;
}
speak = ptr;
speak->speak();
}
exit:
return 0;
}[/php]

dont mind the gotos
You declared the constructor, you never did anything with it, why even add the constructor? Anyways, that's the reason, you declared it, and it's looking for the function to call, but you never declared what the function does.

I really don't know how to explain it...
Quote Originally Posted by Void View Post
You declared the constructor, you never did anything with it, why even add the constructor? Anyways, that's the reason, you declared it, and it's looking for the function to call, but you never declared what the function does.
...i thought i need to declare the constructor anyways....
oh well
Quote Originally Posted by Auxilium View Post


...i thought i need to declare the constructor anyways....
oh well
Naww, if you're not going to take any default parameters just don't bother declaring the constructor.
Roger that.
Solved. Request close is request
~solved and locked~
Posts 16 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?