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 88 89 90 91 92 93 94 95 96 97 98 99 100
|
//knight.h
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Knight
{
private:
string m_name;
int m_stamina;
bool m_onHorse;
Weapon w;
public:
Knight(string, int, string, int, int);
bool onHorse();
};
//knight.cpp
#include "knight.h"
#include "weapon.h"
Knight::Knight(string name, int stamina, string wepName, int missChance, int stamUse)
: m_name(name), m_stamina(stamina), w(wepName, missChance, stamUse)
{
}
bool Knight :: onHorse()
{
if (m_stamina > 0)
{
m_onHorse = true;
}
else
{
m_onHorse = false;
}
}
//weapon.h
#include <iostream>
#include <string>
using namespace std;
class Weapon
{
private:
int stamUse;
int missChance;
string wepName;
public:
Weapon(string, int, int);
};
//weapon.cpp
#include "weapon.h"
Weapon::Weapon(string wepName, int stamUse, int missChance)
:wepName(wepName), stamUse(stamUse), missChance(missChance)
{
}
//main.cpp
#include "Random.h"
#include "knight.h"
#include "weapon.h"
#include <unistd.h>
int main()
{
Knight userKnight(string name, int stamina, string wepName, int missChance, int stamUse);
cout << "What would you like your knight's name to be?" << endl;
getline(cin, name);
cout << name << endl;
return 0;
}
Also there is a random.cpp and random.h file provided by my teacher, but I havent gotten errors using those yet. Errors I am getting are:
g++ Random.cpp knight.cpp weapon.cpp main.cpp -o output
In file included from knight.cpp:1:0:
knight.h:14:5: error: 'Weapon' does not name a type
Weapon* w;
^
knight.cpp: In constructor 'Knight::Knight(std::string, int, std::string, int, i
knight.cpp:4:39: error: class 'Knight' does not have any field named 'w'
: m_name(name), m_stamina(stamina), w(wepName, missChance, stamUse)
^
In file included from main.cpp:2:0:
knight.h:14:5: error: 'Weapon' does not name a type
Weapon w;
^
main.cpp: In function 'int main()':
main.cpp:9:16: error: 'name' was not declared in this scope
getline(cin, name);
Im wondering why my knight class is not recognizing the weapon object given to it in knight.h please help
|