//bow.h
#include <iostream>
#include <string>
using std::string;
class Bow
{
// data member declarations
string colour;
bool drawn;
int numOfArrows;
public:
//constructor
Bow(string aColour);
// destructor
Bow::~Bow();
// methods
void draw();
int fire();
};
//bow.cpp
#include <iostream>
#include <cstring>
#include "bow.h"
class ArcheryCompetition
{
private:
//memeber variables
int rounds;
float redScore;
Bow red;
float blueScore;
Bow blue;
public:
//constructor
ArcheryCompetition(int lrounds);
//destructor
~ArcheryCompetition();
//methods
int compete(void);
};
//constructs an ArcheryCompetition object
ArcheryCompetition::ArcheryCompetition(int lrounds) :
rounds(lrounds), red(Bow("red")),
blue(Bow("blue")), redScore(0), blueScore(0)
{ }
//the destructor
ArcheryCompetition::~ArcheryCompetition()
{
}
//the heart of the game
//walks the player through an entire competition
//and figures out who won
int ArcheryCompetition::compete()
{
using std::cout;
//go through each round, keeping track of the score
for(int i = 0; i < rounds; i++)
{
cout << "now on round " << i+1 << ".\n";
red.draw();
blue.draw();
redScore = (red.fire() + redScore * i)/(i+1) ;
blueScore = (blue.fire() + redScore * i)/(i+1) ;
}
//figure out who won
if(redScore == blueScore)
cout << "We have a tie!!!\n";
elseif(redScore < blueScore)
cout <<"Blue wins her hand!!\n";
else
cout << "red wins her hand!!\n";
return 1;
}
int main(void)
{
//the driver function: constructs the object and calls the appropriate methods
ArcheryCompetition plymouthSquare(2);
plymouthSquare.compete();
return 0;
}
the error is shown as:
1>bow.obj : error LNK2019: unresolved external symbol "public: __thiscall Bow::~Bow(void)" (??1Bow@@QAE@XZ) referenced in function "public: __thiscall ArcheryCompetition::ArcheryCompetition(int)" (??0ArcheryCompetition@@QAE@H@Z)
1>bow.obj : error LNK2019: unresolved external symbol "public: __thiscall Bow::Bow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Bow@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall ArcheryCompetition::ArcheryCompetition(int)" (??0ArcheryCompetition@@QAE@H@Z)
1>bow.obj : error LNK2019: unresolved external symbol "public: int __thiscall Bow::fire(void)" (?fire@Bow@@QAEHXZ) referenced in function "public: int __thiscall ArcheryCompetition::compete(void)" (?compete@ArcheryCompetition@@QAEHXZ)
1>bow.obj : error LNK2019: unresolved external symbol "public: void __thiscall Bow::draw(void)" (?draw@Bow@@QAEXXZ) referenced in function "public: int __thiscall ArcheryCompetition::compete(void)" (?compete@ArcheryCompetition@@QAEHXZ)
1>c:\users\blahblah\documents\visual studio 2010\Projects\test\Debug\test.exe : fatal error LNK1120: 4 unresolved externals
//bow.h
#include <iostream>
#include <string>
using std::string;
class Bow
{
// data member declarations
string colour;
bool drawn;
int numOfArrows;
public:
//constructor
Bow(string aColour);
// destructor
Bow::~Bow();
// methods
void draw();
int fire();
};
//bow.cpp
#include <iostream>
#include <cstring>
#include "bow.h"
class ArcheryCompetition
{
private:
//memeber variables
int rounds;
float redScore;
Bow red;
float blueScore;
Bow blue;
public:
//constructor
ArcheryCompetition(int lrounds);
//destructor
~ArcheryCompetition();
//methods
int compete(void);
};
//constructs an ArcheryCompetition object
ArcheryCompetition::ArcheryCompetition(int lrounds) :
rounds(lrounds), red(Bow("red")),
blue(Bow("blue")), redScore(0), blueScore(0)
{ }
//the destructor
ArcheryCompetition::~ArcheryCompetition()
{
}
//the heart of the game
//walks the player through an entire competition
//and figures out who won
int ArcheryCompetition::compete()
{
using std::cout;
//go through each round, keeping track of the score
for(int i = 0; i < rounds; i++)
{
cout << "now on round " << i+1 << ".\n";
red.draw();
blue.draw();
redScore = (red.fire() + redScore * i)/(i+1) ;
blueScore = (blue.fire() + redScore * i)/(i+1) ;
}
//figure out who won
if(redScore == blueScore)
cout << "We have a tie!!!\n";
elseif(redScore < blueScore)
cout <<"Blue wins her hand!!\n";
else
cout << "red wins her hand!!\n";
return 1;
}
int main(void)
{
//the driver function: constructs the object and calls the appropriate methods
ArcheryCompetition plymouthSquare(2);
plymouthSquare.compete();
return 0;
}
Line 21: Remove Bow::-part This is not used inside a Bow-class definition itself.
How actually you use your bow-class? i mean... where you define all methods for that class? I mean where is your implementations of these?
1 2 3 4
Bow::Bow(string aColour);
Bow::~Bow();
void Bow::draw();
int Bow::fire();
Adding more as/if i find them
Rule of thumb: create class "prototype" in the header file (.h) and the implementation in source file (.cpp). DO NOT implement another classes in other classes source file :)