Hello I have this huge problem whenever I try to compile this code (i'm using the C++ language):
main.cpp
// main.cpp
#include "Wiz.h"
using namespace std;
int main()
{
// Create wizards with specific data.
Wizard wiz0("Gandalf", 25, 100, 10);
Wizard wiz1("Loki", 50, 150, 12);
Wizard wiz2("Magius", 10, 75, 6);
// Create a stream which will transfer the data from
// our program to the specified file "wizdata.tex".
ofstream outFile("wizdata.txt");
// If the file opened correctly then call save methods.
if( outFile )
{
// Dump data into the stream.
wiz0.save(outFile);
wiz1.save(outFile);
wiz2.save(outFile);
outFile.close();
}
}
Wiz.cpp
// Wiz.cpp
#include "Wiz.h"
#include <iostream>
using namespace std;
Wizard::Wizard()
{
mName = "Default";
mHitPoints = 0;
mMagicPoints = 0;
mArmor = 0;
}
Wizard::Wizard(string name, int hp, int mp, int armor)
{
mName = name;
mHitPoints = hp;
mMagicPoints = mp;
mArmor = armor;
}
void Wizard::print()
{
cout << "Name= " << mName << endl;
cout << "HP= " << mHitPoints << endl;
cout << "MP= " << mMagicPoints << endl;
cout << "Armor= " << mArmor << endl;
cout << endl;
}
Wiz.h
// Wiz.h
#ifndef WIZARD_H
#define WIZARD_H
#include <fstream>
#include <string>
class Wizard
{
public:
Wizard();
Wizard(std::string name, int hp, int mp, int armor);
// [...] other methods snipped
void print();
void save(std::ofstream& outFile);
void load(std::ifstream& inFile);
private:
std::string mName;
int mHitPoints;
int mMagicPoints;
int mArmor;
};
#endif // WIZARD_H
And with that compiled I get compile errors as follows:
------ Build started: Project: Saving.Loading, Configuration: Debug Win32 ------
Compiling...
Wiz.cpp
main.cpp
Generating Code...
Linking...
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Wizard::save(class std::basic_ofstream<char,struct std::char_traits<char> > &)" (?save@Wizard@@QAEXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main
Debug/Saving.Loading.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Users\Administrator\Documents\Visual Studio Projects\Saving.Loading\Debug\BuildLog.htm"
Saving.Loading - 2 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped