[SOLVED] LNK2019 unresolved external symbol
I've searched the forms for common causes of this problem, but have not been able to find any misspelled calls.
1 2 3 4 5 6 7 8 9
|
1>Lab05a.obj : error LNK2019: unresolved external symbol "public: __thiscall
Animals::Animals(void)" (??0Animals@@QAE@XZ) referenced in function "void __cdecl
addData(class std::vector<class Animals,class std::allocator<class Animals> > &)" (?
addData@@YAXAAV?$vector@VAnimals@@V?$allocator@VAnimals@@@std@@@std@@@Z)
1>Animals.obj : error LNK2019: unresolved external symbol "public: __thiscall
Animals::Animals(void)" (??0Animals@@QAE@XZ) referenced in function "void __cdecl
`dynamic initializer for 'Animal''(void)" (??__EAnimal@@YAXXZ)
|
Lab05a.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include "Animal.h"
#include <string>
#include <iostream>
#include <vector>
using namespace std;
void addData(vector <Animals> & AnimalData);
void deleteData(vector <Animals> & AnimalData);
void displayData(vector <Animals> & AnimalData);
void displayAllData(const vector <Animals> & AnimalData);
int main()
{
int choice;
vector <Animals> AnimalData; // Vector to hold all of the animal information
do
{
cout << "\n1) Add an animal";
cout << "\n2) Delete an animal";
cout << "\n3) Search for an animal";
cout << "\n4) Display all animals";
cout << "\n5) Exit and kill all animals";
cin >> choice;
switch (choice)
{
case 1:
addData(AnimalData);
break;
case 2:
deleteData(AnimalData);
break;
case 3:
displayData(AnimalData);
break;
case 4:
displayAllData(AnimalData);
break;
case 5:
system("pause");
return 0;
default:
cout << "\nInvalid Choice!";
}
} while (choice != 5);
system("pause");
return 0;
}
void addData(vector <Animals> & AnimalData)
{
string name;
double age;
Animals newAnimal;
cout << "\nEnter the name of the animal: ";
cin >> name;
newAnimal.setName(name);
cout << "\nEnter the age of the animal: ";
cin >> age;
newAnimal.setAge(age);
AnimalData.push_back(newAnimal); // adds newAnimal to AnimalData
}
void deleteData(vector <Animals> & AnimalData)
{
//
}
void displayData(vector <Animals> & AnimalData)
{
//
}
void displayAllData(const vector <Animals> & AnimalData)
{
//
}
|
Animals.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include "Animal.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
Animals Animal;
void Animals::setName(string n)
{
name = n;
}
string Animals::getName() const
{
return name;
}
void Animals::setAge(double a)
{
age = a;
}
double Animals::getAge() const
{
return age;
}
|
Animal.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#ifndef ANIMAL_H
#define ANIMAL_H
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Animals
{
private:
double age;
string name;
public:
Animals();
void setAge(double);
void setName(string);
double getAge() const;
string getName() const;
};
#endif
|
Last edited on
You need to define your default constructor.
Issue seems to be having
in Animals.h
After deleting that line of code the program works flawlessly. I don't really understand why that should have been there in the first place.
Topic archived. No new replies allowed.